diff --git a/resource-manager/streamanalytics/2020-03-01/client.go b/resource-manager/streamanalytics/2020-03-01/client.go index 8e60dcbdf65..ab53c45ab58 100644 --- a/resource-manager/streamanalytics/2020-03-01/client.go +++ b/resource-manager/streamanalytics/2020-03-01/client.go @@ -4,7 +4,8 @@ package v2020_03_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/streamanalytics/2020-03-01/clusters" "github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/functions" "github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/inputs" @@ -13,6 +14,8 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/streamingjobs" "github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/subscriptions" "github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2020-03-01/transformations" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" ) type Client struct { @@ -26,40 +29,63 @@ type Client struct { Transformations *transformations.TransformationsClient } -func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { - - clustersClient := clusters.NewClustersClientWithBaseURI(endpoint) - configureAuthFunc(&clustersClient.Client) - - functionsClient := functions.NewFunctionsClientWithBaseURI(endpoint) - configureAuthFunc(&functionsClient.Client) +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + clustersClient, err := clusters.NewClustersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Clusters client: %+v", err) + } + configureFunc(clustersClient.Client) - inputsClient := inputs.NewInputsClientWithBaseURI(endpoint) - configureAuthFunc(&inputsClient.Client) + functionsClient, err := functions.NewFunctionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Functions client: %+v", err) + } + configureFunc(functionsClient.Client) - outputsClient := outputs.NewOutputsClientWithBaseURI(endpoint) - configureAuthFunc(&outputsClient.Client) + inputsClient, err := inputs.NewInputsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Inputs client: %+v", err) + } + configureFunc(inputsClient.Client) - privateEndpointsClient := privateendpoints.NewPrivateEndpointsClientWithBaseURI(endpoint) - configureAuthFunc(&privateEndpointsClient.Client) + outputsClient, err := outputs.NewOutputsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Outputs client: %+v", err) + } + configureFunc(outputsClient.Client) - streamingJobsClient := streamingjobs.NewStreamingJobsClientWithBaseURI(endpoint) - configureAuthFunc(&streamingJobsClient.Client) + privateEndpointsClient, err := privateendpoints.NewPrivateEndpointsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateEndpoints client: %+v", err) + } + configureFunc(privateEndpointsClient.Client) - subscriptionsClient := subscriptions.NewSubscriptionsClientWithBaseURI(endpoint) - configureAuthFunc(&subscriptionsClient.Client) + streamingJobsClient, err := streamingjobs.NewStreamingJobsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building StreamingJobs client: %+v", err) + } + configureFunc(streamingJobsClient.Client) - transformationsClient := transformations.NewTransformationsClientWithBaseURI(endpoint) - configureAuthFunc(&transformationsClient.Client) + subscriptionsClient, err := subscriptions.NewSubscriptionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Subscriptions client: %+v", err) + } + configureFunc(subscriptionsClient.Client) - return Client{ - Clusters: &clustersClient, - Functions: &functionsClient, - Inputs: &inputsClient, - Outputs: &outputsClient, - PrivateEndpoints: &privateEndpointsClient, - StreamingJobs: &streamingJobsClient, - Subscriptions: &subscriptionsClient, - Transformations: &transformationsClient, + transformationsClient, err := transformations.NewTransformationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Transformations client: %+v", err) } + configureFunc(transformationsClient.Client) + + return &Client{ + Clusters: clustersClient, + Functions: functionsClient, + Inputs: inputsClient, + Outputs: outputsClient, + PrivateEndpoints: privateEndpointsClient, + StreamingJobs: streamingJobsClient, + Subscriptions: subscriptionsClient, + Transformations: transformationsClient, + }, nil } diff --git a/resource-manager/streamanalytics/2020-03-01/clusters/client.go b/resource-manager/streamanalytics/2020-03-01/clusters/client.go index 1e6fabf8cba..e4ab7fd89ad 100644 --- a/resource-manager/streamanalytics/2020-03-01/clusters/client.go +++ b/resource-manager/streamanalytics/2020-03-01/clusters/client.go @@ -1,18 +1,26 @@ package clusters -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 ClustersClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewClustersClientWithBaseURI(endpoint string) ClustersClient { - return ClustersClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewClustersClientWithBaseURI(sdkApi sdkEnv.Api) (*ClustersClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "clusters", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ClustersClient: %+v", err) } + + return &ClustersClient{ + Client: client, + }, nil } diff --git a/resource-manager/streamanalytics/2020-03-01/clusters/constants.go b/resource-manager/streamanalytics/2020-03-01/clusters/constants.go index b2f24dc720b..2df4cceae1f 100644 --- a/resource-manager/streamanalytics/2020-03-01/clusters/constants.go +++ b/resource-manager/streamanalytics/2020-03-01/clusters/constants.go @@ -1,6 +1,10 @@ package clusters -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 PossibleValuesForClusterProvisioningState() []string { } } +func (s *ClusterProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClusterProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseClusterProvisioningState(input string) (*ClusterProvisioningState, error) { vals := map[string]ClusterProvisioningState{ "canceled": ClusterProvisioningStateCanceled, @@ -51,6 +68,19 @@ func PossibleValuesForClusterSkuName() []string { } } +func (s *ClusterSkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClusterSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseClusterSkuName(input string) (*ClusterSkuName, error) { vals := map[string]ClusterSkuName{ "default": ClusterSkuNameDefault, @@ -94,6 +124,19 @@ func PossibleValuesForJobState() []string { } } +func (s *JobState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseJobState(input string) (*JobState, error) { vals := map[string]JobState{ "created": JobStateCreated, diff --git a/resource-manager/streamanalytics/2020-03-01/clusters/method_createorupdate.go b/resource-manager/streamanalytics/2020-03-01/clusters/method_createorupdate.go new file mode 100644 index 00000000000..a0817eb6bed --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/clusters/method_createorupdate.go @@ -0,0 +1,107 @@ +package clusters + +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 CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Cluster +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ClustersClient) CreateOrUpdate(ctx context.Context, id ClusterId, input Cluster, options CreateOrUpdateOperationOptions) (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(), + OptionsObject: options, + } + + 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c ClustersClient) CreateOrUpdateThenPoll(ctx context.Context, id ClusterId, input Cluster, options CreateOrUpdateOperationOptions) error { + result, err := c.CreateOrUpdate(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2020-03-01/clusters/method_createorupdate_autorest.go b/resource-manager/streamanalytics/2020-03-01/clusters/method_createorupdate_autorest.go deleted file mode 100644 index 135ec28277d..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/clusters/method_createorupdate_autorest.go +++ /dev/null @@ -1,114 +0,0 @@ -package clusters - -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 CreateOrUpdateOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *Cluster -} - -type CreateOrUpdateOperationOptions struct { - IfMatch *string - IfNoneMatch *string -} - -func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { - return CreateOrUpdateOperationOptions{} -} - -func (o CreateOrUpdateOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - if o.IfNoneMatch != nil { - out["If-None-Match"] = *o.IfNoneMatch - } - - return out -} - -func (o CreateOrUpdateOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// CreateOrUpdate ... -func (c ClustersClient) CreateOrUpdate(ctx context.Context, id ClusterId, input Cluster, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result, err = c.senderForCreateOrUpdate(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed -func (c ClustersClient) CreateOrUpdateThenPoll(ctx context.Context, id ClusterId, input Cluster, options CreateOrUpdateOperationOptions) error { - result, err := c.CreateOrUpdate(ctx, id, input, options) - if err != nil { - return fmt.Errorf("performing CreateOrUpdate: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after CreateOrUpdate: %+v", err) - } - - return nil -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c ClustersClient) preparerForCreateOrUpdate(ctx context.Context, id ClusterId, input Cluster, options CreateOrUpdateOperationOptions) (*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.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForCreateOrUpdate sends the CreateOrUpdate request. The method will close the -// http.Response Body if it receives an error. -func (c ClustersClient) senderForCreateOrUpdate(ctx context.Context, req *http.Request) (future CreateOrUpdateOperationResponse, 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/streamanalytics/2020-03-01/clusters/method_delete.go b/resource-manager/streamanalytics/2020-03-01/clusters/method_delete.go new file mode 100644 index 00000000000..13e2610ffd6 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/clusters/method_delete.go @@ -0,0 +1,71 @@ +package clusters + +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 +} + +// Delete ... +func (c ClustersClient) Delete(ctx context.Context, id ClusterId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ClustersClient) DeleteThenPoll(ctx context.Context, id ClusterId) 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/streamanalytics/2020-03-01/clusters/method_delete_autorest.go b/resource-manager/streamanalytics/2020-03-01/clusters/method_delete_autorest.go deleted file mode 100644 index 285ecf817e5..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/clusters/method_delete_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package clusters - -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 -} - -// Delete ... -func (c ClustersClient) Delete(ctx context.Context, id ClusterId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "Delete", nil, "Failure preparing request") - return - } - - result, err = c.senderForDelete(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// DeleteThenPoll performs Delete then polls until it's completed -func (c ClustersClient) DeleteThenPoll(ctx context.Context, id ClusterId) 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 ClustersClient) preparerForDelete(ctx context.Context, id ClusterId) (*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 ClustersClient) 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/streamanalytics/2020-03-01/clusters/method_get.go b/resource-manager/streamanalytics/2020-03-01/clusters/method_get.go new file mode 100644 index 00000000000..34ea1e2c3d0 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/clusters/method_get.go @@ -0,0 +1,51 @@ +package clusters + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Cluster +} + +// Get ... +func (c ClustersClient) Get(ctx context.Context, id ClusterId) (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/streamanalytics/2020-03-01/clusters/method_get_autorest.go b/resource-manager/streamanalytics/2020-03-01/clusters/method_get_autorest.go deleted file mode 100644 index 2957d3dd8de..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/clusters/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package clusters - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Cluster -} - -// Get ... -func (c ClustersClient) Get(ctx context.Context, id ClusterId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c ClustersClient) preparerForGet(ctx context.Context, id ClusterId) (*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 ClustersClient) 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/streamanalytics/2020-03-01/clusters/method_listbyresourcegroup.go b/resource-manager/streamanalytics/2020-03-01/clusters/method_listbyresourcegroup.go new file mode 100644 index 00000000000..f78f88ff93e --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/clusters/method_listbyresourcegroup.go @@ -0,0 +1,92 @@ +package clusters + +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 ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Cluster +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Cluster +} + +// ListByResourceGroup ... +func (c ClustersClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.StreamAnalytics/clusters", 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 *[]Cluster `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c ClustersClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ClusterOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ClustersClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ClusterOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Cluster, 0) + + resp, err := c.ListByResourceGroup(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 = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/streamanalytics/2020-03-01/clusters/method_listbyresourcegroup_autorest.go b/resource-manager/streamanalytics/2020-03-01/clusters/method_listbyresourcegroup_autorest.go deleted file mode 100644 index e6a046991d7..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/clusters/method_listbyresourcegroup_autorest.go +++ /dev/null @@ -1,187 +0,0 @@ -package clusters - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "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 ListByResourceGroupOperationResponse struct { - HttpResponse *http.Response - Model *[]Cluster - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) -} - -type ListByResourceGroupCompleteResult struct { - Items []Cluster -} - -func (r ListByResourceGroupOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByResourceGroup ... -func (c ClustersClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { - req, err := c.preparerForListByResourceGroup(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListByResourceGroup", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByResourceGroup(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByResourceGroup prepares the ListByResourceGroup request. -func (c ClustersClient) preparerForListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*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.StreamAnalytics/clusters", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. -func (c ClustersClient) preparerForListByResourceGroupWithNextLink(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)) -} - -// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always -// closes the http.Response Body. -func (c ClustersClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { - type page struct { - Values []Cluster `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 ListByResourceGroupOperationResponse, err error) { - req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListByResourceGroup", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByResourceGroup(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByResourceGroupComplete retrieves all of the results into a single object -func (c ClustersClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { - return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ClusterOperationPredicate{}) -} - -// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ClustersClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ClusterOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { - items := make([]Cluster, 0) - - page, err := c.ListByResourceGroup(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 := ListByResourceGroupCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/streamanalytics/2020-03-01/clusters/method_listbysubscription.go b/resource-manager/streamanalytics/2020-03-01/clusters/method_listbysubscription.go new file mode 100644 index 00000000000..0dd4c65b493 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/clusters/method_listbysubscription.go @@ -0,0 +1,92 @@ +package clusters + +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 ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Cluster +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []Cluster +} + +// ListBySubscription ... +func (c ClustersClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.StreamAnalytics/clusters", 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 *[]Cluster `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySubscriptionComplete retrieves all the results into a single object +func (c ClustersClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, ClusterOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ClustersClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ClusterOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]Cluster, 0) + + resp, err := c.ListBySubscription(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 = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/streamanalytics/2020-03-01/clusters/method_listbysubscription_autorest.go b/resource-manager/streamanalytics/2020-03-01/clusters/method_listbysubscription_autorest.go deleted file mode 100644 index 1601cef41e9..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/clusters/method_listbysubscription_autorest.go +++ /dev/null @@ -1,187 +0,0 @@ -package clusters - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "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 ListBySubscriptionOperationResponse struct { - HttpResponse *http.Response - Model *[]Cluster - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListBySubscriptionOperationResponse, error) -} - -type ListBySubscriptionCompleteResult struct { - Items []Cluster -} - -func (r ListBySubscriptionOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ListBySubscriptionOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListBySubscription ... -func (c ClustersClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ListBySubscriptionOperationResponse, err error) { - req, err := c.preparerForListBySubscription(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListBySubscription", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListBySubscription", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListBySubscription(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListBySubscription", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListBySubscription prepares the ListBySubscription request. -func (c ClustersClient) preparerForListBySubscription(ctx context.Context, id commonids.SubscriptionId) (*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.StreamAnalytics/clusters", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListBySubscriptionWithNextLink prepares the ListBySubscription request with the given nextLink token. -func (c ClustersClient) preparerForListBySubscriptionWithNextLink(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)) -} - -// responderForListBySubscription handles the response to the ListBySubscription request. The method always -// closes the http.Response Body. -func (c ClustersClient) responderForListBySubscription(resp *http.Response) (result ListBySubscriptionOperationResponse, err error) { - type page struct { - Values []Cluster `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 ListBySubscriptionOperationResponse, err error) { - req, err := c.preparerForListBySubscriptionWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListBySubscription", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListBySubscription", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListBySubscription(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListBySubscription", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListBySubscriptionComplete retrieves all of the results into a single object -func (c ClustersClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { - return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, ClusterOperationPredicate{}) -} - -// ListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ClustersClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ClusterOperationPredicate) (resp ListBySubscriptionCompleteResult, err error) { - items := make([]Cluster, 0) - - page, err := c.ListBySubscription(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 := ListBySubscriptionCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/streamanalytics/2020-03-01/clusters/method_liststreamingjobs.go b/resource-manager/streamanalytics/2020-03-01/clusters/method_liststreamingjobs.go new file mode 100644 index 00000000000..e31f18a1172 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/clusters/method_liststreamingjobs.go @@ -0,0 +1,91 @@ +package clusters + +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 ListStreamingJobsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ClusterJob +} + +type ListStreamingJobsCompleteResult struct { + LatestHttpResponse *http.Response + Items []ClusterJob +} + +// ListStreamingJobs ... +func (c ClustersClient) ListStreamingJobs(ctx context.Context, id ClusterId) (result ListStreamingJobsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listStreamingJobs", 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 *[]ClusterJob `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListStreamingJobsComplete retrieves all the results into a single object +func (c ClustersClient) ListStreamingJobsComplete(ctx context.Context, id ClusterId) (ListStreamingJobsCompleteResult, error) { + return c.ListStreamingJobsCompleteMatchingPredicate(ctx, id, ClusterJobOperationPredicate{}) +} + +// ListStreamingJobsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ClustersClient) ListStreamingJobsCompleteMatchingPredicate(ctx context.Context, id ClusterId, predicate ClusterJobOperationPredicate) (result ListStreamingJobsCompleteResult, err error) { + items := make([]ClusterJob, 0) + + resp, err := c.ListStreamingJobs(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 = ListStreamingJobsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/streamanalytics/2020-03-01/clusters/method_liststreamingjobs_autorest.go b/resource-manager/streamanalytics/2020-03-01/clusters/method_liststreamingjobs_autorest.go deleted file mode 100644 index 09d1fdaa06d..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/clusters/method_liststreamingjobs_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package clusters - -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 ListStreamingJobsOperationResponse struct { - HttpResponse *http.Response - Model *[]ClusterJob - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListStreamingJobsOperationResponse, error) -} - -type ListStreamingJobsCompleteResult struct { - Items []ClusterJob -} - -func (r ListStreamingJobsOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListStreamingJobsOperationResponse) LoadMore(ctx context.Context) (resp ListStreamingJobsOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListStreamingJobs ... -func (c ClustersClient) ListStreamingJobs(ctx context.Context, id ClusterId) (resp ListStreamingJobsOperationResponse, err error) { - req, err := c.preparerForListStreamingJobs(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListStreamingJobs", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListStreamingJobs", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListStreamingJobs(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListStreamingJobs", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListStreamingJobs prepares the ListStreamingJobs request. -func (c ClustersClient) preparerForListStreamingJobs(ctx context.Context, id ClusterId) (*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/listStreamingJobs", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListStreamingJobsWithNextLink prepares the ListStreamingJobs request with the given nextLink token. -func (c ClustersClient) preparerForListStreamingJobsWithNextLink(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)) -} - -// responderForListStreamingJobs handles the response to the ListStreamingJobs request. The method always -// closes the http.Response Body. -func (c ClustersClient) responderForListStreamingJobs(resp *http.Response) (result ListStreamingJobsOperationResponse, err error) { - type page struct { - Values []ClusterJob `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 ListStreamingJobsOperationResponse, err error) { - req, err := c.preparerForListStreamingJobsWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListStreamingJobs", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListStreamingJobs", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListStreamingJobs(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "ListStreamingJobs", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListStreamingJobsComplete retrieves all of the results into a single object -func (c ClustersClient) ListStreamingJobsComplete(ctx context.Context, id ClusterId) (ListStreamingJobsCompleteResult, error) { - return c.ListStreamingJobsCompleteMatchingPredicate(ctx, id, ClusterJobOperationPredicate{}) -} - -// ListStreamingJobsCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c ClustersClient) ListStreamingJobsCompleteMatchingPredicate(ctx context.Context, id ClusterId, predicate ClusterJobOperationPredicate) (resp ListStreamingJobsCompleteResult, err error) { - items := make([]ClusterJob, 0) - - page, err := c.ListStreamingJobs(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 := ListStreamingJobsCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/streamanalytics/2020-03-01/clusters/method_update.go b/resource-manager/streamanalytics/2020-03-01/clusters/method_update.go new file mode 100644 index 00000000000..dd58409344a --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/clusters/method_update.go @@ -0,0 +1,103 @@ +package clusters + +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 UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Cluster +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c ClustersClient) Update(ctx context.Context, id ClusterId, input Cluster, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + OptionsObject: options, + } + + 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ClustersClient) UpdateThenPoll(ctx context.Context, id ClusterId, input Cluster, options UpdateOperationOptions) error { + result, err := c.Update(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2020-03-01/clusters/method_update_autorest.go b/resource-manager/streamanalytics/2020-03-01/clusters/method_update_autorest.go deleted file mode 100644 index 7cbf16e70dd..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/clusters/method_update_autorest.go +++ /dev/null @@ -1,109 +0,0 @@ -package clusters - -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 UpdateOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *Cluster -} - -type UpdateOperationOptions struct { - IfMatch *string -} - -func DefaultUpdateOperationOptions() UpdateOperationOptions { - return UpdateOperationOptions{} -} - -func (o UpdateOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - return out -} - -func (o UpdateOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// Update ... -func (c ClustersClient) Update(ctx context.Context, id ClusterId, input Cluster, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "Update", nil, "Failure preparing request") - return - } - - result, err = c.senderForUpdate(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "clusters.ClustersClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// UpdateThenPoll performs Update then polls until it's completed -func (c ClustersClient) UpdateThenPoll(ctx context.Context, id ClusterId, input Cluster, options UpdateOperationOptions) error { - result, err := c.Update(ctx, id, input, options) - if err != nil { - return fmt.Errorf("performing Update: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Update: %+v", err) - } - - return nil -} - -// preparerForUpdate prepares the Update request. -func (c ClustersClient) preparerForUpdate(ctx context.Context, id ClusterId, input Cluster, options UpdateOperationOptions) (*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.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForUpdate sends the Update request. The method will close the -// http.Response Body if it receives an error. -func (c ClustersClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, 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/streamanalytics/2020-03-01/functions/client.go b/resource-manager/streamanalytics/2020-03-01/functions/client.go index d8478486d96..07fdb1da32c 100644 --- a/resource-manager/streamanalytics/2020-03-01/functions/client.go +++ b/resource-manager/streamanalytics/2020-03-01/functions/client.go @@ -1,18 +1,26 @@ package functions -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 FunctionsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewFunctionsClientWithBaseURI(endpoint string) FunctionsClient { - return FunctionsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewFunctionsClientWithBaseURI(sdkApi sdkEnv.Api) (*FunctionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "functions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating FunctionsClient: %+v", err) } + + return &FunctionsClient{ + Client: client, + }, nil } diff --git a/resource-manager/streamanalytics/2020-03-01/functions/constants.go b/resource-manager/streamanalytics/2020-03-01/functions/constants.go index 48971992b3d..70e2a07f3ec 100644 --- a/resource-manager/streamanalytics/2020-03-01/functions/constants.go +++ b/resource-manager/streamanalytics/2020-03-01/functions/constants.go @@ -1,6 +1,10 @@ package functions -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 PossibleValuesForUdfType() []string { } } +func (s *UdfType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUdfType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseUdfType(input string) (*UdfType, error) { vals := map[string]UdfType{ "scalar": UdfTypeScalar, diff --git a/resource-manager/streamanalytics/2020-03-01/functions/method_createorreplace.go b/resource-manager/streamanalytics/2020-03-01/functions/method_createorreplace.go new file mode 100644 index 00000000000..022771aa3df --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/functions/method_createorreplace.go @@ -0,0 +1,89 @@ +package functions + +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 CreateOrReplaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Function +} + +type CreateOrReplaceOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { + return CreateOrReplaceOperationOptions{} +} + +func (o CreateOrReplaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrReplaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrReplaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrReplace ... +func (c FunctionsClient) CreateOrReplace(ctx context.Context, id FunctionId, input Function, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2020-03-01/functions/method_createorreplace_autorest.go b/resource-manager/streamanalytics/2020-03-01/functions/method_createorreplace_autorest.go deleted file mode 100644 index 96bd230c74e..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/functions/method_createorreplace_autorest.go +++ /dev/null @@ -1,103 +0,0 @@ -package functions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrReplaceOperationResponse struct { - HttpResponse *http.Response - Model *Function -} - -type CreateOrReplaceOperationOptions struct { - IfMatch *string - IfNoneMatch *string -} - -func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { - return CreateOrReplaceOperationOptions{} -} - -func (o CreateOrReplaceOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - if o.IfNoneMatch != nil { - out["If-None-Match"] = *o.IfNoneMatch - } - - return out -} - -func (o CreateOrReplaceOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// CreateOrReplace ... -func (c FunctionsClient) CreateOrReplace(ctx context.Context, id FunctionId, input Function, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { - req, err := c.preparerForCreateOrReplace(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "CreateOrReplace", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "CreateOrReplace", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrReplace(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "CreateOrReplace", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrReplace prepares the CreateOrReplace request. -func (c FunctionsClient) preparerForCreateOrReplace(ctx context.Context, id FunctionId, input Function, options CreateOrReplaceOperationOptions) (*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.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrReplace handles the response to the CreateOrReplace request. The method always -// closes the http.Response Body. -func (c FunctionsClient) responderForCreateOrReplace(resp *http.Response) (result CreateOrReplaceOperationResponse, 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/streamanalytics/2020-03-01/functions/method_delete.go b/resource-manager/streamanalytics/2020-03-01/functions/method_delete.go new file mode 100644 index 00000000000..9332b8f72c8 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/functions/method_delete.go @@ -0,0 +1,47 @@ +package functions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 FunctionsClient) Delete(ctx context.Context, id FunctionId) (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/streamanalytics/2020-03-01/functions/method_delete_autorest.go b/resource-manager/streamanalytics/2020-03-01/functions/method_delete_autorest.go deleted file mode 100644 index 460f6ac3da9..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/functions/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package functions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 FunctionsClient) Delete(ctx context.Context, id FunctionId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c FunctionsClient) preparerForDelete(ctx context.Context, id FunctionId) (*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 FunctionsClient) 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/streamanalytics/2020-03-01/functions/method_get.go b/resource-manager/streamanalytics/2020-03-01/functions/method_get.go new file mode 100644 index 00000000000..8fe532bc9c6 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/functions/method_get.go @@ -0,0 +1,51 @@ +package functions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Function +} + +// Get ... +func (c FunctionsClient) Get(ctx context.Context, id FunctionId) (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/streamanalytics/2020-03-01/functions/method_get_autorest.go b/resource-manager/streamanalytics/2020-03-01/functions/method_get_autorest.go deleted file mode 100644 index b531eff94b5..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/functions/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package functions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Function -} - -// Get ... -func (c FunctionsClient) Get(ctx context.Context, id FunctionId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c FunctionsClient) preparerForGet(ctx context.Context, id FunctionId) (*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 FunctionsClient) 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/streamanalytics/2020-03-01/functions/method_listbystreamingjob.go b/resource-manager/streamanalytics/2020-03-01/functions/method_listbystreamingjob.go new file mode 100644 index 00000000000..690bfe011ed --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/functions/method_listbystreamingjob.go @@ -0,0 +1,119 @@ +package functions + +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 ListByStreamingJobOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Function +} + +type ListByStreamingJobCompleteResult struct { + LatestHttpResponse *http.Response + Items []Function +} + +type ListByStreamingJobOperationOptions struct { + Select *string +} + +func DefaultListByStreamingJobOperationOptions() ListByStreamingJobOperationOptions { + return ListByStreamingJobOperationOptions{} +} + +func (o ListByStreamingJobOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByStreamingJobOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByStreamingJobOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Select != nil { + out.Append("$select", fmt.Sprintf("%v", *o.Select)) + } + return &out +} + +// ListByStreamingJob ... +func (c FunctionsClient) ListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (result ListByStreamingJobOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/functions", 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 *[]Function `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByStreamingJobComplete retrieves all the results into a single object +func (c FunctionsClient) ListByStreamingJobComplete(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (ListByStreamingJobCompleteResult, error) { + return c.ListByStreamingJobCompleteMatchingPredicate(ctx, id, options, FunctionOperationPredicate{}) +} + +// ListByStreamingJobCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FunctionsClient) ListByStreamingJobCompleteMatchingPredicate(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions, predicate FunctionOperationPredicate) (result ListByStreamingJobCompleteResult, err error) { + items := make([]Function, 0) + + resp, err := c.ListByStreamingJob(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 = ListByStreamingJobCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/streamanalytics/2020-03-01/functions/method_listbystreamingjob_autorest.go b/resource-manager/streamanalytics/2020-03-01/functions/method_listbystreamingjob_autorest.go deleted file mode 100644 index 2f3271a3c78..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/functions/method_listbystreamingjob_autorest.go +++ /dev/null @@ -1,215 +0,0 @@ -package functions - -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 ListByStreamingJobOperationResponse struct { - HttpResponse *http.Response - Model *[]Function - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByStreamingJobOperationResponse, error) -} - -type ListByStreamingJobCompleteResult struct { - Items []Function -} - -func (r ListByStreamingJobOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByStreamingJobOperationResponse) LoadMore(ctx context.Context) (resp ListByStreamingJobOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListByStreamingJobOperationOptions struct { - Select *string -} - -func DefaultListByStreamingJobOperationOptions() ListByStreamingJobOperationOptions { - return ListByStreamingJobOperationOptions{} -} - -func (o ListByStreamingJobOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListByStreamingJobOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Select != nil { - out["$select"] = *o.Select - } - - return out -} - -// ListByStreamingJob ... -func (c FunctionsClient) ListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (resp ListByStreamingJobOperationResponse, err error) { - req, err := c.preparerForListByStreamingJob(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "ListByStreamingJob", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "ListByStreamingJob", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByStreamingJob(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "ListByStreamingJob", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByStreamingJob prepares the ListByStreamingJob request. -func (c FunctionsClient) preparerForListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (*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/functions", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByStreamingJobWithNextLink prepares the ListByStreamingJob request with the given nextLink token. -func (c FunctionsClient) preparerForListByStreamingJobWithNextLink(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)) -} - -// responderForListByStreamingJob handles the response to the ListByStreamingJob request. The method always -// closes the http.Response Body. -func (c FunctionsClient) responderForListByStreamingJob(resp *http.Response) (result ListByStreamingJobOperationResponse, err error) { - type page struct { - Values []Function `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 ListByStreamingJobOperationResponse, err error) { - req, err := c.preparerForListByStreamingJobWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "ListByStreamingJob", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "ListByStreamingJob", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByStreamingJob(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "ListByStreamingJob", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByStreamingJobComplete retrieves all of the results into a single object -func (c FunctionsClient) ListByStreamingJobComplete(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (ListByStreamingJobCompleteResult, error) { - return c.ListByStreamingJobCompleteMatchingPredicate(ctx, id, options, FunctionOperationPredicate{}) -} - -// ListByStreamingJobCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c FunctionsClient) ListByStreamingJobCompleteMatchingPredicate(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions, predicate FunctionOperationPredicate) (resp ListByStreamingJobCompleteResult, err error) { - items := make([]Function, 0) - - page, err := c.ListByStreamingJob(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 := ListByStreamingJobCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/streamanalytics/2020-03-01/functions/method_retrievedefaultdefinition.go b/resource-manager/streamanalytics/2020-03-01/functions/method_retrievedefaultdefinition.go new file mode 100644 index 00000000000..0b5970fbb25 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/functions/method_retrievedefaultdefinition.go @@ -0,0 +1,56 @@ +package functions + +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 RetrieveDefaultDefinitionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Function +} + +// RetrieveDefaultDefinition ... +func (c FunctionsClient) RetrieveDefaultDefinition(ctx context.Context, id FunctionId, input FunctionRetrieveDefaultDefinitionParameters) (result RetrieveDefaultDefinitionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/retrieveDefaultDefinition", 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/streamanalytics/2020-03-01/functions/method_retrievedefaultdefinition_autorest.go b/resource-manager/streamanalytics/2020-03-01/functions/method_retrievedefaultdefinition_autorest.go deleted file mode 100644 index 3be1fb89bd6..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/functions/method_retrievedefaultdefinition_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package functions - -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 RetrieveDefaultDefinitionOperationResponse struct { - HttpResponse *http.Response - Model *Function -} - -// RetrieveDefaultDefinition ... -func (c FunctionsClient) RetrieveDefaultDefinition(ctx context.Context, id FunctionId, input FunctionRetrieveDefaultDefinitionParameters) (result RetrieveDefaultDefinitionOperationResponse, err error) { - req, err := c.preparerForRetrieveDefaultDefinition(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "RetrieveDefaultDefinition", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "RetrieveDefaultDefinition", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForRetrieveDefaultDefinition(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "RetrieveDefaultDefinition", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForRetrieveDefaultDefinition prepares the RetrieveDefaultDefinition request. -func (c FunctionsClient) preparerForRetrieveDefaultDefinition(ctx context.Context, id FunctionId, input FunctionRetrieveDefaultDefinitionParameters) (*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/retrieveDefaultDefinition", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForRetrieveDefaultDefinition handles the response to the RetrieveDefaultDefinition request. The method always -// closes the http.Response Body. -func (c FunctionsClient) responderForRetrieveDefaultDefinition(resp *http.Response) (result RetrieveDefaultDefinitionOperationResponse, 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/streamanalytics/2020-03-01/functions/method_test.go b/resource-manager/streamanalytics/2020-03-01/functions/method_test.go new file mode 100644 index 00000000000..f50d7238966 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/functions/method_test.go @@ -0,0 +1,75 @@ +package functions + +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 TestOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ResourceTestStatus +} + +// Test ... +func (c FunctionsClient) Test(ctx context.Context, id FunctionId, input Function) (result TestOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/test", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// TestThenPoll performs Test then polls until it's completed +func (c FunctionsClient) TestThenPoll(ctx context.Context, id FunctionId, input Function) error { + result, err := c.Test(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Test: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Test: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2020-03-01/functions/method_test_autorest.go b/resource-manager/streamanalytics/2020-03-01/functions/method_test_autorest.go deleted file mode 100644 index 40c3044f720..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/functions/method_test_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package functions - -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 TestOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *ResourceTestStatus -} - -// Test ... -func (c FunctionsClient) Test(ctx context.Context, id FunctionId, input Function) (result TestOperationResponse, err error) { - req, err := c.preparerForTest(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Test", nil, "Failure preparing request") - return - } - - result, err = c.senderForTest(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Test", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// TestThenPoll performs Test then polls until it's completed -func (c FunctionsClient) TestThenPoll(ctx context.Context, id FunctionId, input Function) error { - result, err := c.Test(ctx, id, input) - if err != nil { - return fmt.Errorf("performing Test: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Test: %+v", err) - } - - return nil -} - -// preparerForTest prepares the Test request. -func (c FunctionsClient) preparerForTest(ctx context.Context, id FunctionId, input Function) (*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/test", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForTest sends the Test request. The method will close the -// http.Response Body if it receives an error. -func (c FunctionsClient) senderForTest(ctx context.Context, req *http.Request) (future TestOperationResponse, 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/streamanalytics/2020-03-01/functions/method_update.go b/resource-manager/streamanalytics/2020-03-01/functions/method_update.go new file mode 100644 index 00000000000..af905ccf9c8 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/functions/method_update.go @@ -0,0 +1,84 @@ +package functions + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Function +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c FunctionsClient) Update(ctx context.Context, id FunctionId, input Function, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2020-03-01/functions/method_update_autorest.go b/resource-manager/streamanalytics/2020-03-01/functions/method_update_autorest.go deleted file mode 100644 index 07b0dd63c19..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/functions/method_update_autorest.go +++ /dev/null @@ -1,98 +0,0 @@ -package functions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Function -} - -type UpdateOperationOptions struct { - IfMatch *string -} - -func DefaultUpdateOperationOptions() UpdateOperationOptions { - return UpdateOperationOptions{} -} - -func (o UpdateOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - return out -} - -func (o UpdateOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// Update ... -func (c FunctionsClient) Update(ctx context.Context, id FunctionId, input Function, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c FunctionsClient) preparerForUpdate(ctx context.Context, id FunctionId, input Function, options UpdateOperationOptions) (*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.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - 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 FunctionsClient) 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/streamanalytics/2020-03-01/inputs/client.go b/resource-manager/streamanalytics/2020-03-01/inputs/client.go index 859c2802c38..fa5493aa37f 100644 --- a/resource-manager/streamanalytics/2020-03-01/inputs/client.go +++ b/resource-manager/streamanalytics/2020-03-01/inputs/client.go @@ -1,18 +1,26 @@ package inputs -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 InputsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewInputsClientWithBaseURI(endpoint string) InputsClient { - return InputsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewInputsClientWithBaseURI(sdkApi sdkEnv.Api) (*InputsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "inputs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating InputsClient: %+v", err) } + + return &InputsClient{ + Client: client, + }, nil } diff --git a/resource-manager/streamanalytics/2020-03-01/inputs/constants.go b/resource-manager/streamanalytics/2020-03-01/inputs/constants.go index 6ba7df2d418..2471858f017 100644 --- a/resource-manager/streamanalytics/2020-03-01/inputs/constants.go +++ b/resource-manager/streamanalytics/2020-03-01/inputs/constants.go @@ -1,6 +1,10 @@ package inputs -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 PossibleValuesForAuthenticationMode() []string { } } +func (s *AuthenticationMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAuthenticationMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAuthenticationMode(input string) (*AuthenticationMode, error) { vals := map[string]AuthenticationMode{ "connectionstring": AuthenticationModeConnectionString, @@ -52,6 +69,19 @@ func PossibleValuesForCompressionType() []string { } } +func (s *CompressionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCompressionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCompressionType(input string) (*CompressionType, error) { vals := map[string]CompressionType{ "deflate": CompressionTypeDeflate, @@ -79,6 +109,19 @@ func PossibleValuesForEncoding() []string { } } +func (s *Encoding) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEncoding(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEncoding(input string) (*Encoding, error) { vals := map[string]Encoding{ "utf8": EncodingUTFEight, @@ -110,6 +153,19 @@ func PossibleValuesForEventSerializationType() []string { } } +func (s *EventSerializationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventSerializationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventSerializationType(input string) (*EventSerializationType, error) { vals := map[string]EventSerializationType{ "avro": EventSerializationTypeAvro, @@ -140,6 +196,19 @@ func PossibleValuesForJsonOutputSerializationFormat() []string { } } +func (s *JsonOutputSerializationFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJsonOutputSerializationFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseJsonOutputSerializationFormat(input string) (*JsonOutputSerializationFormat, error) { vals := map[string]JsonOutputSerializationFormat{ "array": JsonOutputSerializationFormatArray, @@ -170,6 +239,19 @@ func PossibleValuesForRefreshType() []string { } } +func (s *RefreshType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRefreshType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRefreshType(input string) (*RefreshType, error) { vals := map[string]RefreshType{ "refreshperiodicallywithdelta": RefreshTypeRefreshPeriodicallyWithDelta, diff --git a/resource-manager/streamanalytics/2020-03-01/inputs/method_createorreplace.go b/resource-manager/streamanalytics/2020-03-01/inputs/method_createorreplace.go new file mode 100644 index 00000000000..6337031f48a --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/inputs/method_createorreplace.go @@ -0,0 +1,89 @@ +package inputs + +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 CreateOrReplaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Input +} + +type CreateOrReplaceOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { + return CreateOrReplaceOperationOptions{} +} + +func (o CreateOrReplaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrReplaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrReplaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrReplace ... +func (c InputsClient) CreateOrReplace(ctx context.Context, id InputId, input Input, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2020-03-01/inputs/method_createorreplace_autorest.go b/resource-manager/streamanalytics/2020-03-01/inputs/method_createorreplace_autorest.go deleted file mode 100644 index ea3a65c3426..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/inputs/method_createorreplace_autorest.go +++ /dev/null @@ -1,103 +0,0 @@ -package inputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrReplaceOperationResponse struct { - HttpResponse *http.Response - Model *Input -} - -type CreateOrReplaceOperationOptions struct { - IfMatch *string - IfNoneMatch *string -} - -func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { - return CreateOrReplaceOperationOptions{} -} - -func (o CreateOrReplaceOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - if o.IfNoneMatch != nil { - out["If-None-Match"] = *o.IfNoneMatch - } - - return out -} - -func (o CreateOrReplaceOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// CreateOrReplace ... -func (c InputsClient) CreateOrReplace(ctx context.Context, id InputId, input Input, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { - req, err := c.preparerForCreateOrReplace(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "CreateOrReplace", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "CreateOrReplace", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrReplace(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "CreateOrReplace", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrReplace prepares the CreateOrReplace request. -func (c InputsClient) preparerForCreateOrReplace(ctx context.Context, id InputId, input Input, options CreateOrReplaceOperationOptions) (*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.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrReplace handles the response to the CreateOrReplace request. The method always -// closes the http.Response Body. -func (c InputsClient) responderForCreateOrReplace(resp *http.Response) (result CreateOrReplaceOperationResponse, 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/streamanalytics/2020-03-01/inputs/method_delete.go b/resource-manager/streamanalytics/2020-03-01/inputs/method_delete.go new file mode 100644 index 00000000000..000c88164d1 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/inputs/method_delete.go @@ -0,0 +1,47 @@ +package inputs + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 InputsClient) Delete(ctx context.Context, id InputId) (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/streamanalytics/2020-03-01/inputs/method_delete_autorest.go b/resource-manager/streamanalytics/2020-03-01/inputs/method_delete_autorest.go deleted file mode 100644 index 0df6db9b503..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/inputs/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package inputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 InputsClient) Delete(ctx context.Context, id InputId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c InputsClient) preparerForDelete(ctx context.Context, id InputId) (*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 InputsClient) 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/streamanalytics/2020-03-01/inputs/method_get.go b/resource-manager/streamanalytics/2020-03-01/inputs/method_get.go new file mode 100644 index 00000000000..e108d651002 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/inputs/method_get.go @@ -0,0 +1,51 @@ +package inputs + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Input +} + +// Get ... +func (c InputsClient) Get(ctx context.Context, id InputId) (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/streamanalytics/2020-03-01/inputs/method_get_autorest.go b/resource-manager/streamanalytics/2020-03-01/inputs/method_get_autorest.go deleted file mode 100644 index bb6e886dfcb..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/inputs/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package inputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Input -} - -// Get ... -func (c InputsClient) Get(ctx context.Context, id InputId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c InputsClient) preparerForGet(ctx context.Context, id InputId) (*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 InputsClient) 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/streamanalytics/2020-03-01/inputs/method_listbystreamingjob.go b/resource-manager/streamanalytics/2020-03-01/inputs/method_listbystreamingjob.go new file mode 100644 index 00000000000..6fd6245baf2 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/inputs/method_listbystreamingjob.go @@ -0,0 +1,119 @@ +package inputs + +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 ListByStreamingJobOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Input +} + +type ListByStreamingJobCompleteResult struct { + LatestHttpResponse *http.Response + Items []Input +} + +type ListByStreamingJobOperationOptions struct { + Select *string +} + +func DefaultListByStreamingJobOperationOptions() ListByStreamingJobOperationOptions { + return ListByStreamingJobOperationOptions{} +} + +func (o ListByStreamingJobOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByStreamingJobOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByStreamingJobOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Select != nil { + out.Append("$select", fmt.Sprintf("%v", *o.Select)) + } + return &out +} + +// ListByStreamingJob ... +func (c InputsClient) ListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (result ListByStreamingJobOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/inputs", 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 *[]Input `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByStreamingJobComplete retrieves all the results into a single object +func (c InputsClient) ListByStreamingJobComplete(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (ListByStreamingJobCompleteResult, error) { + return c.ListByStreamingJobCompleteMatchingPredicate(ctx, id, options, InputOperationPredicate{}) +} + +// ListByStreamingJobCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c InputsClient) ListByStreamingJobCompleteMatchingPredicate(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions, predicate InputOperationPredicate) (result ListByStreamingJobCompleteResult, err error) { + items := make([]Input, 0) + + resp, err := c.ListByStreamingJob(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 = ListByStreamingJobCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/streamanalytics/2020-03-01/inputs/method_listbystreamingjob_autorest.go b/resource-manager/streamanalytics/2020-03-01/inputs/method_listbystreamingjob_autorest.go deleted file mode 100644 index a86ec923786..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/inputs/method_listbystreamingjob_autorest.go +++ /dev/null @@ -1,215 +0,0 @@ -package inputs - -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 ListByStreamingJobOperationResponse struct { - HttpResponse *http.Response - Model *[]Input - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByStreamingJobOperationResponse, error) -} - -type ListByStreamingJobCompleteResult struct { - Items []Input -} - -func (r ListByStreamingJobOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByStreamingJobOperationResponse) LoadMore(ctx context.Context) (resp ListByStreamingJobOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListByStreamingJobOperationOptions struct { - Select *string -} - -func DefaultListByStreamingJobOperationOptions() ListByStreamingJobOperationOptions { - return ListByStreamingJobOperationOptions{} -} - -func (o ListByStreamingJobOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListByStreamingJobOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Select != nil { - out["$select"] = *o.Select - } - - return out -} - -// ListByStreamingJob ... -func (c InputsClient) ListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (resp ListByStreamingJobOperationResponse, err error) { - req, err := c.preparerForListByStreamingJob(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "ListByStreamingJob", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "ListByStreamingJob", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByStreamingJob(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "ListByStreamingJob", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByStreamingJob prepares the ListByStreamingJob request. -func (c InputsClient) preparerForListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (*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/inputs", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByStreamingJobWithNextLink prepares the ListByStreamingJob request with the given nextLink token. -func (c InputsClient) preparerForListByStreamingJobWithNextLink(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)) -} - -// responderForListByStreamingJob handles the response to the ListByStreamingJob request. The method always -// closes the http.Response Body. -func (c InputsClient) responderForListByStreamingJob(resp *http.Response) (result ListByStreamingJobOperationResponse, err error) { - type page struct { - Values []Input `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 ListByStreamingJobOperationResponse, err error) { - req, err := c.preparerForListByStreamingJobWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "ListByStreamingJob", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "ListByStreamingJob", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByStreamingJob(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "ListByStreamingJob", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByStreamingJobComplete retrieves all of the results into a single object -func (c InputsClient) ListByStreamingJobComplete(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (ListByStreamingJobCompleteResult, error) { - return c.ListByStreamingJobCompleteMatchingPredicate(ctx, id, options, InputOperationPredicate{}) -} - -// ListByStreamingJobCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c InputsClient) ListByStreamingJobCompleteMatchingPredicate(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions, predicate InputOperationPredicate) (resp ListByStreamingJobCompleteResult, err error) { - items := make([]Input, 0) - - page, err := c.ListByStreamingJob(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 := ListByStreamingJobCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/streamanalytics/2020-03-01/inputs/method_test.go b/resource-manager/streamanalytics/2020-03-01/inputs/method_test.go new file mode 100644 index 00000000000..6fff5988979 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/inputs/method_test.go @@ -0,0 +1,75 @@ +package inputs + +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 TestOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ResourceTestStatus +} + +// Test ... +func (c InputsClient) Test(ctx context.Context, id InputId, input Input) (result TestOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/test", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// TestThenPoll performs Test then polls until it's completed +func (c InputsClient) TestThenPoll(ctx context.Context, id InputId, input Input) error { + result, err := c.Test(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Test: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Test: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2020-03-01/inputs/method_test_autorest.go b/resource-manager/streamanalytics/2020-03-01/inputs/method_test_autorest.go deleted file mode 100644 index ec55575caea..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/inputs/method_test_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package inputs - -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 TestOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *ResourceTestStatus -} - -// Test ... -func (c InputsClient) Test(ctx context.Context, id InputId, input Input) (result TestOperationResponse, err error) { - req, err := c.preparerForTest(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Test", nil, "Failure preparing request") - return - } - - result, err = c.senderForTest(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Test", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// TestThenPoll performs Test then polls until it's completed -func (c InputsClient) TestThenPoll(ctx context.Context, id InputId, input Input) error { - result, err := c.Test(ctx, id, input) - if err != nil { - return fmt.Errorf("performing Test: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Test: %+v", err) - } - - return nil -} - -// preparerForTest prepares the Test request. -func (c InputsClient) preparerForTest(ctx context.Context, id InputId, input Input) (*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/test", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForTest sends the Test request. The method will close the -// http.Response Body if it receives an error. -func (c InputsClient) senderForTest(ctx context.Context, req *http.Request) (future TestOperationResponse, 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/streamanalytics/2020-03-01/inputs/method_update.go b/resource-manager/streamanalytics/2020-03-01/inputs/method_update.go new file mode 100644 index 00000000000..8816b664425 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/inputs/method_update.go @@ -0,0 +1,84 @@ +package inputs + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Input +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c InputsClient) Update(ctx context.Context, id InputId, input Input, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2020-03-01/inputs/method_update_autorest.go b/resource-manager/streamanalytics/2020-03-01/inputs/method_update_autorest.go deleted file mode 100644 index a6e3027501a..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/inputs/method_update_autorest.go +++ /dev/null @@ -1,98 +0,0 @@ -package inputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Input -} - -type UpdateOperationOptions struct { - IfMatch *string -} - -func DefaultUpdateOperationOptions() UpdateOperationOptions { - return UpdateOperationOptions{} -} - -func (o UpdateOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - return out -} - -func (o UpdateOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// Update ... -func (c InputsClient) Update(ctx context.Context, id InputId, input Input, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c InputsClient) preparerForUpdate(ctx context.Context, id InputId, input Input, options UpdateOperationOptions) (*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.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - 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 InputsClient) 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/streamanalytics/2020-03-01/outputs/client.go b/resource-manager/streamanalytics/2020-03-01/outputs/client.go index 90cdaf9a2f3..a14d848cb27 100644 --- a/resource-manager/streamanalytics/2020-03-01/outputs/client.go +++ b/resource-manager/streamanalytics/2020-03-01/outputs/client.go @@ -1,18 +1,26 @@ package outputs -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 OutputsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewOutputsClientWithBaseURI(endpoint string) OutputsClient { - return OutputsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewOutputsClientWithBaseURI(sdkApi sdkEnv.Api) (*OutputsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "outputs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating OutputsClient: %+v", err) } + + return &OutputsClient{ + Client: client, + }, nil } diff --git a/resource-manager/streamanalytics/2020-03-01/outputs/constants.go b/resource-manager/streamanalytics/2020-03-01/outputs/constants.go index d4d4105abc6..e8e90fb7450 100644 --- a/resource-manager/streamanalytics/2020-03-01/outputs/constants.go +++ b/resource-manager/streamanalytics/2020-03-01/outputs/constants.go @@ -1,6 +1,10 @@ package outputs -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 PossibleValuesForAuthenticationMode() []string { } } +func (s *AuthenticationMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAuthenticationMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAuthenticationMode(input string) (*AuthenticationMode, error) { vals := map[string]AuthenticationMode{ "connectionstring": AuthenticationModeConnectionString, @@ -48,6 +65,19 @@ func PossibleValuesForEncoding() []string { } } +func (s *Encoding) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEncoding(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEncoding(input string) (*Encoding, error) { vals := map[string]Encoding{ "utf8": EncodingUTFEight, @@ -79,6 +109,19 @@ func PossibleValuesForEventSerializationType() []string { } } +func (s *EventSerializationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventSerializationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventSerializationType(input string) (*EventSerializationType, error) { vals := map[string]EventSerializationType{ "avro": EventSerializationTypeAvro, @@ -109,6 +152,19 @@ func PossibleValuesForJsonOutputSerializationFormat() []string { } } +func (s *JsonOutputSerializationFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJsonOutputSerializationFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseJsonOutputSerializationFormat(input string) (*JsonOutputSerializationFormat, error) { vals := map[string]JsonOutputSerializationFormat{ "array": JsonOutputSerializationFormatArray, diff --git a/resource-manager/streamanalytics/2020-03-01/outputs/method_createorreplace.go b/resource-manager/streamanalytics/2020-03-01/outputs/method_createorreplace.go new file mode 100644 index 00000000000..ca182b4586c --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/outputs/method_createorreplace.go @@ -0,0 +1,89 @@ +package outputs + +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 CreateOrReplaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Output +} + +type CreateOrReplaceOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { + return CreateOrReplaceOperationOptions{} +} + +func (o CreateOrReplaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrReplaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrReplaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrReplace ... +func (c OutputsClient) CreateOrReplace(ctx context.Context, id OutputId, input Output, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2020-03-01/outputs/method_createorreplace_autorest.go b/resource-manager/streamanalytics/2020-03-01/outputs/method_createorreplace_autorest.go deleted file mode 100644 index 4d25b5c5877..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/outputs/method_createorreplace_autorest.go +++ /dev/null @@ -1,103 +0,0 @@ -package outputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrReplaceOperationResponse struct { - HttpResponse *http.Response - Model *Output -} - -type CreateOrReplaceOperationOptions struct { - IfMatch *string - IfNoneMatch *string -} - -func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { - return CreateOrReplaceOperationOptions{} -} - -func (o CreateOrReplaceOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - if o.IfNoneMatch != nil { - out["If-None-Match"] = *o.IfNoneMatch - } - - return out -} - -func (o CreateOrReplaceOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// CreateOrReplace ... -func (c OutputsClient) CreateOrReplace(ctx context.Context, id OutputId, input Output, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { - req, err := c.preparerForCreateOrReplace(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "CreateOrReplace", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "CreateOrReplace", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrReplace(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "CreateOrReplace", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrReplace prepares the CreateOrReplace request. -func (c OutputsClient) preparerForCreateOrReplace(ctx context.Context, id OutputId, input Output, options CreateOrReplaceOperationOptions) (*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.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrReplace handles the response to the CreateOrReplace request. The method always -// closes the http.Response Body. -func (c OutputsClient) responderForCreateOrReplace(resp *http.Response) (result CreateOrReplaceOperationResponse, 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/streamanalytics/2020-03-01/outputs/method_delete.go b/resource-manager/streamanalytics/2020-03-01/outputs/method_delete.go new file mode 100644 index 00000000000..7abe427d104 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/outputs/method_delete.go @@ -0,0 +1,47 @@ +package outputs + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 OutputsClient) Delete(ctx context.Context, id OutputId) (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/streamanalytics/2020-03-01/outputs/method_delete_autorest.go b/resource-manager/streamanalytics/2020-03-01/outputs/method_delete_autorest.go deleted file mode 100644 index 9ba461f884f..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/outputs/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package outputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 OutputsClient) Delete(ctx context.Context, id OutputId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c OutputsClient) preparerForDelete(ctx context.Context, id OutputId) (*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 OutputsClient) 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/streamanalytics/2020-03-01/outputs/method_get.go b/resource-manager/streamanalytics/2020-03-01/outputs/method_get.go new file mode 100644 index 00000000000..f0eee6a3d1c --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/outputs/method_get.go @@ -0,0 +1,51 @@ +package outputs + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Output +} + +// Get ... +func (c OutputsClient) Get(ctx context.Context, id OutputId) (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/streamanalytics/2020-03-01/outputs/method_get_autorest.go b/resource-manager/streamanalytics/2020-03-01/outputs/method_get_autorest.go deleted file mode 100644 index 11f1639925b..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/outputs/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package outputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Output -} - -// Get ... -func (c OutputsClient) Get(ctx context.Context, id OutputId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c OutputsClient) preparerForGet(ctx context.Context, id OutputId) (*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 OutputsClient) 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/streamanalytics/2020-03-01/outputs/method_listbystreamingjob.go b/resource-manager/streamanalytics/2020-03-01/outputs/method_listbystreamingjob.go new file mode 100644 index 00000000000..42acfe0a467 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/outputs/method_listbystreamingjob.go @@ -0,0 +1,119 @@ +package outputs + +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 ListByStreamingJobOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Output +} + +type ListByStreamingJobCompleteResult struct { + LatestHttpResponse *http.Response + Items []Output +} + +type ListByStreamingJobOperationOptions struct { + Select *string +} + +func DefaultListByStreamingJobOperationOptions() ListByStreamingJobOperationOptions { + return ListByStreamingJobOperationOptions{} +} + +func (o ListByStreamingJobOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByStreamingJobOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByStreamingJobOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Select != nil { + out.Append("$select", fmt.Sprintf("%v", *o.Select)) + } + return &out +} + +// ListByStreamingJob ... +func (c OutputsClient) ListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (result ListByStreamingJobOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/outputs", 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 *[]Output `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByStreamingJobComplete retrieves all the results into a single object +func (c OutputsClient) ListByStreamingJobComplete(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (ListByStreamingJobCompleteResult, error) { + return c.ListByStreamingJobCompleteMatchingPredicate(ctx, id, options, OutputOperationPredicate{}) +} + +// ListByStreamingJobCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c OutputsClient) ListByStreamingJobCompleteMatchingPredicate(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions, predicate OutputOperationPredicate) (result ListByStreamingJobCompleteResult, err error) { + items := make([]Output, 0) + + resp, err := c.ListByStreamingJob(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 = ListByStreamingJobCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/streamanalytics/2020-03-01/outputs/method_listbystreamingjob_autorest.go b/resource-manager/streamanalytics/2020-03-01/outputs/method_listbystreamingjob_autorest.go deleted file mode 100644 index b0dae7269a0..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/outputs/method_listbystreamingjob_autorest.go +++ /dev/null @@ -1,215 +0,0 @@ -package outputs - -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 ListByStreamingJobOperationResponse struct { - HttpResponse *http.Response - Model *[]Output - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByStreamingJobOperationResponse, error) -} - -type ListByStreamingJobCompleteResult struct { - Items []Output -} - -func (r ListByStreamingJobOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByStreamingJobOperationResponse) LoadMore(ctx context.Context) (resp ListByStreamingJobOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListByStreamingJobOperationOptions struct { - Select *string -} - -func DefaultListByStreamingJobOperationOptions() ListByStreamingJobOperationOptions { - return ListByStreamingJobOperationOptions{} -} - -func (o ListByStreamingJobOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListByStreamingJobOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Select != nil { - out["$select"] = *o.Select - } - - return out -} - -// ListByStreamingJob ... -func (c OutputsClient) ListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (resp ListByStreamingJobOperationResponse, err error) { - req, err := c.preparerForListByStreamingJob(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "ListByStreamingJob", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "ListByStreamingJob", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByStreamingJob(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "ListByStreamingJob", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByStreamingJob prepares the ListByStreamingJob request. -func (c OutputsClient) preparerForListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (*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/outputs", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByStreamingJobWithNextLink prepares the ListByStreamingJob request with the given nextLink token. -func (c OutputsClient) preparerForListByStreamingJobWithNextLink(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)) -} - -// responderForListByStreamingJob handles the response to the ListByStreamingJob request. The method always -// closes the http.Response Body. -func (c OutputsClient) responderForListByStreamingJob(resp *http.Response) (result ListByStreamingJobOperationResponse, err error) { - type page struct { - Values []Output `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 ListByStreamingJobOperationResponse, err error) { - req, err := c.preparerForListByStreamingJobWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "ListByStreamingJob", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "ListByStreamingJob", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByStreamingJob(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "ListByStreamingJob", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByStreamingJobComplete retrieves all of the results into a single object -func (c OutputsClient) ListByStreamingJobComplete(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (ListByStreamingJobCompleteResult, error) { - return c.ListByStreamingJobCompleteMatchingPredicate(ctx, id, options, OutputOperationPredicate{}) -} - -// ListByStreamingJobCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c OutputsClient) ListByStreamingJobCompleteMatchingPredicate(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions, predicate OutputOperationPredicate) (resp ListByStreamingJobCompleteResult, err error) { - items := make([]Output, 0) - - page, err := c.ListByStreamingJob(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 := ListByStreamingJobCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/streamanalytics/2020-03-01/outputs/method_test.go b/resource-manager/streamanalytics/2020-03-01/outputs/method_test.go new file mode 100644 index 00000000000..7979047cc1d --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/outputs/method_test.go @@ -0,0 +1,75 @@ +package outputs + +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 TestOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ResourceTestStatus +} + +// Test ... +func (c OutputsClient) Test(ctx context.Context, id OutputId, input Output) (result TestOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/test", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// TestThenPoll performs Test then polls until it's completed +func (c OutputsClient) TestThenPoll(ctx context.Context, id OutputId, input Output) error { + result, err := c.Test(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Test: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Test: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2020-03-01/outputs/method_test_autorest.go b/resource-manager/streamanalytics/2020-03-01/outputs/method_test_autorest.go deleted file mode 100644 index 0469b557cab..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/outputs/method_test_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package outputs - -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 TestOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *ResourceTestStatus -} - -// Test ... -func (c OutputsClient) Test(ctx context.Context, id OutputId, input Output) (result TestOperationResponse, err error) { - req, err := c.preparerForTest(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Test", nil, "Failure preparing request") - return - } - - result, err = c.senderForTest(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Test", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// TestThenPoll performs Test then polls until it's completed -func (c OutputsClient) TestThenPoll(ctx context.Context, id OutputId, input Output) error { - result, err := c.Test(ctx, id, input) - if err != nil { - return fmt.Errorf("performing Test: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Test: %+v", err) - } - - return nil -} - -// preparerForTest prepares the Test request. -func (c OutputsClient) preparerForTest(ctx context.Context, id OutputId, input Output) (*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/test", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForTest sends the Test request. The method will close the -// http.Response Body if it receives an error. -func (c OutputsClient) senderForTest(ctx context.Context, req *http.Request) (future TestOperationResponse, 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/streamanalytics/2020-03-01/outputs/method_update.go b/resource-manager/streamanalytics/2020-03-01/outputs/method_update.go new file mode 100644 index 00000000000..b373774238c --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/outputs/method_update.go @@ -0,0 +1,84 @@ +package outputs + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Output +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c OutputsClient) Update(ctx context.Context, id OutputId, input Output, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2020-03-01/outputs/method_update_autorest.go b/resource-manager/streamanalytics/2020-03-01/outputs/method_update_autorest.go deleted file mode 100644 index 6ca83b47aa9..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/outputs/method_update_autorest.go +++ /dev/null @@ -1,98 +0,0 @@ -package outputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Output -} - -type UpdateOperationOptions struct { - IfMatch *string -} - -func DefaultUpdateOperationOptions() UpdateOperationOptions { - return UpdateOperationOptions{} -} - -func (o UpdateOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - return out -} - -func (o UpdateOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// Update ... -func (c OutputsClient) Update(ctx context.Context, id OutputId, input Output, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c OutputsClient) preparerForUpdate(ctx context.Context, id OutputId, input Output, options UpdateOperationOptions) (*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.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - 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 OutputsClient) 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/streamanalytics/2020-03-01/privateendpoints/client.go b/resource-manager/streamanalytics/2020-03-01/privateendpoints/client.go index fa0a5ad4e66..149437b1334 100644 --- a/resource-manager/streamanalytics/2020-03-01/privateendpoints/client.go +++ b/resource-manager/streamanalytics/2020-03-01/privateendpoints/client.go @@ -1,18 +1,26 @@ package privateendpoints -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 PrivateEndpointsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewPrivateEndpointsClientWithBaseURI(endpoint string) PrivateEndpointsClient { - return PrivateEndpointsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewPrivateEndpointsClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateEndpointsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "privateendpoints", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateEndpointsClient: %+v", err) } + + return &PrivateEndpointsClient{ + Client: client, + }, nil } diff --git a/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_createorupdate.go b/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_createorupdate.go new file mode 100644 index 00000000000..b9597a7ebe2 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_createorupdate.go @@ -0,0 +1,89 @@ +package privateendpoints + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpoint +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c PrivateEndpointsClient) CreateOrUpdate(ctx context.Context, id PrivateEndpointId, input PrivateEndpoint, options CreateOrUpdateOperationOptions) (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(), + OptionsObject: options, + } + + 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/streamanalytics/2020-03-01/privateendpoints/method_createorupdate_autorest.go b/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_createorupdate_autorest.go deleted file mode 100644 index d9fd2fd7fd2..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_createorupdate_autorest.go +++ /dev/null @@ -1,103 +0,0 @@ -package privateendpoints - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *PrivateEndpoint -} - -type CreateOrUpdateOperationOptions struct { - IfMatch *string - IfNoneMatch *string -} - -func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { - return CreateOrUpdateOperationOptions{} -} - -func (o CreateOrUpdateOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - if o.IfNoneMatch != nil { - out["If-None-Match"] = *o.IfNoneMatch - } - - return out -} - -func (o CreateOrUpdateOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// CreateOrUpdate ... -func (c PrivateEndpointsClient) CreateOrUpdate(ctx context.Context, id PrivateEndpointId, input PrivateEndpoint, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { - req, err := c.preparerForCreateOrUpdate(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpoints.PrivateEndpointsClient", "CreateOrUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpoints.PrivateEndpointsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpoints.PrivateEndpointsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrUpdate prepares the CreateOrUpdate request. -func (c PrivateEndpointsClient) preparerForCreateOrUpdate(ctx context.Context, id PrivateEndpointId, input PrivateEndpoint, options CreateOrUpdateOperationOptions) (*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.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - 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 PrivateEndpointsClient) 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/streamanalytics/2020-03-01/privateendpoints/method_delete.go b/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_delete.go new file mode 100644 index 00000000000..70f382bf8e3 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_delete.go @@ -0,0 +1,71 @@ +package privateendpoints + +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 +} + +// Delete ... +func (c PrivateEndpointsClient) Delete(ctx context.Context, id PrivateEndpointId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PrivateEndpointsClient) DeleteThenPoll(ctx context.Context, id PrivateEndpointId) 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/streamanalytics/2020-03-01/privateendpoints/method_delete_autorest.go b/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_delete_autorest.go deleted file mode 100644 index 975fcaec88f..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_delete_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package privateendpoints - -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 -} - -// Delete ... -func (c PrivateEndpointsClient) Delete(ctx context.Context, id PrivateEndpointId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpoints.PrivateEndpointsClient", "Delete", nil, "Failure preparing request") - return - } - - result, err = c.senderForDelete(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpoints.PrivateEndpointsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// DeleteThenPoll performs Delete then polls until it's completed -func (c PrivateEndpointsClient) DeleteThenPoll(ctx context.Context, id PrivateEndpointId) 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 PrivateEndpointsClient) preparerForDelete(ctx context.Context, id PrivateEndpointId) (*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 PrivateEndpointsClient) 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/streamanalytics/2020-03-01/privateendpoints/method_get.go b/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_get.go new file mode 100644 index 00000000000..6f709c83ec2 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_get.go @@ -0,0 +1,51 @@ +package privateendpoints + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *PrivateEndpoint +} + +// Get ... +func (c PrivateEndpointsClient) Get(ctx context.Context, id PrivateEndpointId) (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/streamanalytics/2020-03-01/privateendpoints/method_get_autorest.go b/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_get_autorest.go deleted file mode 100644 index df15ef43fdc..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package privateendpoints - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *PrivateEndpoint -} - -// Get ... -func (c PrivateEndpointsClient) Get(ctx context.Context, id PrivateEndpointId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpoints.PrivateEndpointsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpoints.PrivateEndpointsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpoints.PrivateEndpointsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c PrivateEndpointsClient) preparerForGet(ctx context.Context, id PrivateEndpointId) (*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 PrivateEndpointsClient) 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/streamanalytics/2020-03-01/privateendpoints/method_listbycluster.go b/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_listbycluster.go new file mode 100644 index 00000000000..c29c78543a1 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_listbycluster.go @@ -0,0 +1,91 @@ +package privateendpoints + +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 ListByClusterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateEndpoint +} + +type ListByClusterCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateEndpoint +} + +// ListByCluster ... +func (c PrivateEndpointsClient) ListByCluster(ctx context.Context, id ClusterId) (result ListByClusterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateEndpoints", 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 *[]PrivateEndpoint `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByClusterComplete retrieves all the results into a single object +func (c PrivateEndpointsClient) ListByClusterComplete(ctx context.Context, id ClusterId) (ListByClusterCompleteResult, error) { + return c.ListByClusterCompleteMatchingPredicate(ctx, id, PrivateEndpointOperationPredicate{}) +} + +// ListByClusterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateEndpointsClient) ListByClusterCompleteMatchingPredicate(ctx context.Context, id ClusterId, predicate PrivateEndpointOperationPredicate) (result ListByClusterCompleteResult, err error) { + items := make([]PrivateEndpoint, 0) + + resp, err := c.ListByCluster(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 = ListByClusterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_listbycluster_autorest.go b/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_listbycluster_autorest.go deleted file mode 100644 index 4d3fb50466a..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/privateendpoints/method_listbycluster_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package privateendpoints - -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 ListByClusterOperationResponse struct { - HttpResponse *http.Response - Model *[]PrivateEndpoint - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByClusterOperationResponse, error) -} - -type ListByClusterCompleteResult struct { - Items []PrivateEndpoint -} - -func (r ListByClusterOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByClusterOperationResponse) LoadMore(ctx context.Context) (resp ListByClusterOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ListByCluster ... -func (c PrivateEndpointsClient) ListByCluster(ctx context.Context, id ClusterId) (resp ListByClusterOperationResponse, err error) { - req, err := c.preparerForListByCluster(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpoints.PrivateEndpointsClient", "ListByCluster", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpoints.PrivateEndpointsClient", "ListByCluster", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByCluster(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpoints.PrivateEndpointsClient", "ListByCluster", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByCluster prepares the ListByCluster request. -func (c PrivateEndpointsClient) preparerForListByCluster(ctx context.Context, id ClusterId) (*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/privateEndpoints", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByClusterWithNextLink prepares the ListByCluster request with the given nextLink token. -func (c PrivateEndpointsClient) preparerForListByClusterWithNextLink(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)) -} - -// responderForListByCluster handles the response to the ListByCluster request. The method always -// closes the http.Response Body. -func (c PrivateEndpointsClient) responderForListByCluster(resp *http.Response) (result ListByClusterOperationResponse, err error) { - type page struct { - Values []PrivateEndpoint `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 ListByClusterOperationResponse, err error) { - req, err := c.preparerForListByClusterWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpoints.PrivateEndpointsClient", "ListByCluster", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpoints.PrivateEndpointsClient", "ListByCluster", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByCluster(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "privateendpoints.PrivateEndpointsClient", "ListByCluster", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByClusterComplete retrieves all of the results into a single object -func (c PrivateEndpointsClient) ListByClusterComplete(ctx context.Context, id ClusterId) (ListByClusterCompleteResult, error) { - return c.ListByClusterCompleteMatchingPredicate(ctx, id, PrivateEndpointOperationPredicate{}) -} - -// ListByClusterCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c PrivateEndpointsClient) ListByClusterCompleteMatchingPredicate(ctx context.Context, id ClusterId, predicate PrivateEndpointOperationPredicate) (resp ListByClusterCompleteResult, err error) { - items := make([]PrivateEndpoint, 0) - - page, err := c.ListByCluster(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 := ListByClusterCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/streamanalytics/2020-03-01/streamingjobs/client.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/client.go index 0e0a6976291..2e04ee218cc 100644 --- a/resource-manager/streamanalytics/2020-03-01/streamingjobs/client.go +++ b/resource-manager/streamanalytics/2020-03-01/streamingjobs/client.go @@ -1,18 +1,26 @@ package streamingjobs -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 StreamingJobsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewStreamingJobsClientWithBaseURI(endpoint string) StreamingJobsClient { - return StreamingJobsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewStreamingJobsClientWithBaseURI(sdkApi sdkEnv.Api) (*StreamingJobsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "streamingjobs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating StreamingJobsClient: %+v", err) } + + return &StreamingJobsClient{ + Client: client, + }, nil } diff --git a/resource-manager/streamanalytics/2020-03-01/streamingjobs/constants.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/constants.go index 74654076221..384668567af 100644 --- a/resource-manager/streamanalytics/2020-03-01/streamingjobs/constants.go +++ b/resource-manager/streamanalytics/2020-03-01/streamingjobs/constants.go @@ -1,6 +1,10 @@ package streamingjobs -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 PossibleValuesForAuthenticationMode() []string { } } +func (s *AuthenticationMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAuthenticationMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAuthenticationMode(input string) (*AuthenticationMode, error) { vals := map[string]AuthenticationMode{ "connectionstring": AuthenticationModeConnectionString, @@ -50,6 +67,19 @@ func PossibleValuesForCompatibilityLevel() []string { } } +func (s *CompatibilityLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCompatibilityLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCompatibilityLevel(input string) (*CompatibilityLevel, error) { vals := map[string]CompatibilityLevel{ "1.2": CompatibilityLevelOnePointTwo, @@ -80,6 +110,19 @@ func PossibleValuesForCompressionType() []string { } } +func (s *CompressionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCompressionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCompressionType(input string) (*CompressionType, error) { vals := map[string]CompressionType{ "deflate": CompressionTypeDeflate, @@ -109,6 +152,19 @@ func PossibleValuesForContentStoragePolicy() []string { } } +func (s *ContentStoragePolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContentStoragePolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseContentStoragePolicy(input string) (*ContentStoragePolicy, error) { vals := map[string]ContentStoragePolicy{ "jobstorageaccount": ContentStoragePolicyJobStorageAccount, @@ -135,6 +191,19 @@ func PossibleValuesForEncoding() []string { } } +func (s *Encoding) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEncoding(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEncoding(input string) (*Encoding, error) { vals := map[string]Encoding{ "utf8": EncodingUTFEight, @@ -166,6 +235,19 @@ func PossibleValuesForEventSerializationType() []string { } } +func (s *EventSerializationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventSerializationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventSerializationType(input string) (*EventSerializationType, error) { vals := map[string]EventSerializationType{ "avro": EventSerializationTypeAvro, @@ -196,6 +278,19 @@ func PossibleValuesForEventsOutOfOrderPolicy() []string { } } +func (s *EventsOutOfOrderPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventsOutOfOrderPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventsOutOfOrderPolicy(input string) (*EventsOutOfOrderPolicy, error) { vals := map[string]EventsOutOfOrderPolicy{ "adjust": EventsOutOfOrderPolicyAdjust, @@ -224,6 +319,19 @@ func PossibleValuesForJobType() []string { } } +func (s *JobType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseJobType(input string) (*JobType, error) { vals := map[string]JobType{ "cloud": JobTypeCloud, @@ -252,6 +360,19 @@ func PossibleValuesForJsonOutputSerializationFormat() []string { } } +func (s *JsonOutputSerializationFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJsonOutputSerializationFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseJsonOutputSerializationFormat(input string) (*JsonOutputSerializationFormat, error) { vals := map[string]JsonOutputSerializationFormat{ "array": JsonOutputSerializationFormatArray, @@ -280,6 +401,19 @@ func PossibleValuesForOutputErrorPolicy() []string { } } +func (s *OutputErrorPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOutputErrorPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOutputErrorPolicy(input string) (*OutputErrorPolicy, error) { vals := map[string]OutputErrorPolicy{ "drop": OutputErrorPolicyDrop, @@ -310,6 +444,19 @@ func PossibleValuesForOutputStartMode() []string { } } +func (s *OutputStartMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOutputStartMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOutputStartMode(input string) (*OutputStartMode, error) { vals := map[string]OutputStartMode{ "customtime": OutputStartModeCustomTime, @@ -341,6 +488,19 @@ func PossibleValuesForRefreshType() []string { } } +func (s *RefreshType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRefreshType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRefreshType(input string) (*RefreshType, error) { vals := map[string]RefreshType{ "refreshperiodicallywithdelta": RefreshTypeRefreshPeriodicallyWithDelta, @@ -368,6 +528,19 @@ func PossibleValuesForSkuName() []string { } } +func (s *SkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSkuName(input string) (*SkuName, error) { vals := map[string]SkuName{ "standard": SkuNameStandard, diff --git a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_createorreplace.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_createorreplace.go new file mode 100644 index 00000000000..95d9cbcf619 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_createorreplace.go @@ -0,0 +1,107 @@ +package streamingjobs + +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 CreateOrReplaceOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *StreamingJob +} + +type CreateOrReplaceOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { + return CreateOrReplaceOperationOptions{} +} + +func (o CreateOrReplaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrReplaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrReplaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrReplace ... +func (c StreamingJobsClient) CreateOrReplace(ctx context.Context, id StreamingJobId, input StreamingJob, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + OptionsObject: options, + } + + 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrReplaceThenPoll performs CreateOrReplace then polls until it's completed +func (c StreamingJobsClient) CreateOrReplaceThenPoll(ctx context.Context, id StreamingJobId, input StreamingJob, options CreateOrReplaceOperationOptions) error { + result, err := c.CreateOrReplace(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing CreateOrReplace: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrReplace: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_createorreplace_autorest.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_createorreplace_autorest.go deleted file mode 100644 index 3813ba88427..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_createorreplace_autorest.go +++ /dev/null @@ -1,114 +0,0 @@ -package streamingjobs - -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 CreateOrReplaceOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *StreamingJob -} - -type CreateOrReplaceOperationOptions struct { - IfMatch *string - IfNoneMatch *string -} - -func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { - return CreateOrReplaceOperationOptions{} -} - -func (o CreateOrReplaceOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - if o.IfNoneMatch != nil { - out["If-None-Match"] = *o.IfNoneMatch - } - - return out -} - -func (o CreateOrReplaceOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// CreateOrReplace ... -func (c StreamingJobsClient) CreateOrReplace(ctx context.Context, id StreamingJobId, input StreamingJob, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { - req, err := c.preparerForCreateOrReplace(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "CreateOrReplace", nil, "Failure preparing request") - return - } - - result, err = c.senderForCreateOrReplace(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "CreateOrReplace", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// CreateOrReplaceThenPoll performs CreateOrReplace then polls until it's completed -func (c StreamingJobsClient) CreateOrReplaceThenPoll(ctx context.Context, id StreamingJobId, input StreamingJob, options CreateOrReplaceOperationOptions) error { - result, err := c.CreateOrReplace(ctx, id, input, options) - if err != nil { - return fmt.Errorf("performing CreateOrReplace: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after CreateOrReplace: %+v", err) - } - - return nil -} - -// preparerForCreateOrReplace prepares the CreateOrReplace request. -func (c StreamingJobsClient) preparerForCreateOrReplace(ctx context.Context, id StreamingJobId, input StreamingJob, options CreateOrReplaceOperationOptions) (*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.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForCreateOrReplace sends the CreateOrReplace request. The method will close the -// http.Response Body if it receives an error. -func (c StreamingJobsClient) senderForCreateOrReplace(ctx context.Context, req *http.Request) (future CreateOrReplaceOperationResponse, 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/streamanalytics/2020-03-01/streamingjobs/method_delete.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_delete.go new file mode 100644 index 00000000000..57b2d02ea09 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_delete.go @@ -0,0 +1,71 @@ +package streamingjobs + +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 +} + +// Delete ... +func (c StreamingJobsClient) Delete(ctx context.Context, id StreamingJobId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c StreamingJobsClient) DeleteThenPoll(ctx context.Context, id StreamingJobId) 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/streamanalytics/2020-03-01/streamingjobs/method_delete_autorest.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_delete_autorest.go deleted file mode 100644 index d619132add7..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_delete_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package streamingjobs - -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 -} - -// Delete ... -func (c StreamingJobsClient) Delete(ctx context.Context, id StreamingJobId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Delete", nil, "Failure preparing request") - return - } - - result, err = c.senderForDelete(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// DeleteThenPoll performs Delete then polls until it's completed -func (c StreamingJobsClient) DeleteThenPoll(ctx context.Context, id StreamingJobId) 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 StreamingJobsClient) preparerForDelete(ctx context.Context, id StreamingJobId) (*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 StreamingJobsClient) 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/streamanalytics/2020-03-01/streamingjobs/method_get.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_get.go new file mode 100644 index 00000000000..3594e9721c5 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_get.go @@ -0,0 +1,80 @@ +package streamingjobs + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StreamingJob +} + +type GetOperationOptions struct { + Expand *string +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// Get ... +func (c StreamingJobsClient) Get(ctx context.Context, id StreamingJobId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: 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/streamanalytics/2020-03-01/streamingjobs/method_get_autorest.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_get_autorest.go deleted file mode 100644 index f50e1aaa9e8..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_get_autorest.go +++ /dev/null @@ -1,97 +0,0 @@ -package streamingjobs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *StreamingJob -} - -type GetOperationOptions struct { - Expand *string -} - -func DefaultGetOperationOptions() GetOperationOptions { - return GetOperationOptions{} -} - -func (o GetOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o GetOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Expand != nil { - out["$expand"] = *o.Expand - } - - return out -} - -// Get ... -func (c StreamingJobsClient) Get(ctx context.Context, id StreamingJobId, options GetOperationOptions) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c StreamingJobsClient) preparerForGet(ctx context.Context, id StreamingJobId, options GetOperationOptions) (*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(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 StreamingJobsClient) 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/streamanalytics/2020-03-01/streamingjobs/method_list.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_list.go new file mode 100644 index 00000000000..c2043fdc026 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_list.go @@ -0,0 +1,120 @@ +package streamingjobs + +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 ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StreamingJob +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []StreamingJob +} + +type ListOperationOptions struct { + Expand *string +} + +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.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// List ... +func (c StreamingJobsClient) List(ctx context.Context, id commonids.SubscriptionId, 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.StreamAnalytics/streamingJobs", 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 *[]StreamingJob `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 StreamingJobsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, StreamingJobOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StreamingJobsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate StreamingJobOperationPredicate) (result ListCompleteResult, err error) { + items := make([]StreamingJob, 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/streamanalytics/2020-03-01/streamingjobs/method_list_autorest.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_list_autorest.go deleted file mode 100644 index 9c325f2f221..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_list_autorest.go +++ /dev/null @@ -1,216 +0,0 @@ -package streamingjobs - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "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 ListOperationResponse struct { - HttpResponse *http.Response - Model *[]StreamingJob - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []StreamingJob -} - -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 { - Expand *string -} - -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.Expand != nil { - out["$expand"] = *o.Expand - } - - return out -} - -// List ... -func (c StreamingJobsClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c StreamingJobsClient) preparerForList(ctx context.Context, id commonids.SubscriptionId, 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.StreamAnalytics/streamingJobs", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c StreamingJobsClient) 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 StreamingJobsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []StreamingJob `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, "streamingjobs.StreamingJobsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c StreamingJobsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, StreamingJobOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c StreamingJobsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate StreamingJobOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]StreamingJob, 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/streamanalytics/2020-03-01/streamingjobs/method_listbyresourcegroup.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_listbyresourcegroup.go new file mode 100644 index 00000000000..10f76548945 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_listbyresourcegroup.go @@ -0,0 +1,120 @@ +package streamingjobs + +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 ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StreamingJob +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []StreamingJob +} + +type ListByResourceGroupOperationOptions struct { + Expand *string +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// ListByResourceGroup ... +func (c StreamingJobsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.StreamAnalytics/streamingJobs", 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 *[]StreamingJob `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c StreamingJobsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, StreamingJobOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StreamingJobsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate StreamingJobOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]StreamingJob, 0) + + resp, err := c.ListByResourceGroup(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 = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_listbyresourcegroup_autorest.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_listbyresourcegroup_autorest.go deleted file mode 100644 index 97037ff2975..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_listbyresourcegroup_autorest.go +++ /dev/null @@ -1,216 +0,0 @@ -package streamingjobs - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "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 ListByResourceGroupOperationResponse struct { - HttpResponse *http.Response - Model *[]StreamingJob - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) -} - -type ListByResourceGroupCompleteResult struct { - Items []StreamingJob -} - -func (r ListByResourceGroupOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListByResourceGroupOperationOptions struct { - Expand *string -} - -func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { - return ListByResourceGroupOperationOptions{} -} - -func (o ListByResourceGroupOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListByResourceGroupOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Expand != nil { - out["$expand"] = *o.Expand - } - - return out -} - -// ListByResourceGroup ... -func (c StreamingJobsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (resp ListByResourceGroupOperationResponse, err error) { - req, err := c.preparerForListByResourceGroup(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "ListByResourceGroup", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByResourceGroup(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByResourceGroup prepares the ListByResourceGroup request. -func (c StreamingJobsClient) preparerForListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (*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.StreamAnalytics/streamingJobs", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. -func (c StreamingJobsClient) preparerForListByResourceGroupWithNextLink(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)) -} - -// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always -// closes the http.Response Body. -func (c StreamingJobsClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { - type page struct { - Values []StreamingJob `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 ListByResourceGroupOperationResponse, err error) { - req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "ListByResourceGroup", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByResourceGroup(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByResourceGroupComplete retrieves all of the results into a single object -func (c StreamingJobsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { - return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, StreamingJobOperationPredicate{}) -} - -// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c StreamingJobsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate StreamingJobOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { - items := make([]StreamingJob, 0) - - page, err := c.ListByResourceGroup(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 := ListByResourceGroupCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_scale.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_scale.go new file mode 100644 index 00000000000..cfc6be30fe9 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_scale.go @@ -0,0 +1,74 @@ +package streamingjobs + +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 ScaleOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Scale ... +func (c StreamingJobsClient) Scale(ctx context.Context, id StreamingJobId, input ScaleStreamingJobParameters) (result ScaleOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/scale", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ScaleThenPoll performs Scale then polls until it's completed +func (c StreamingJobsClient) ScaleThenPoll(ctx context.Context, id StreamingJobId, input ScaleStreamingJobParameters) error { + result, err := c.Scale(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Scale: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Scale: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_scale_autorest.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_scale_autorest.go deleted file mode 100644 index 5a54d0da2f4..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_scale_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package streamingjobs - -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 ScaleOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// Scale ... -func (c StreamingJobsClient) Scale(ctx context.Context, id StreamingJobId, input ScaleStreamingJobParameters) (result ScaleOperationResponse, err error) { - req, err := c.preparerForScale(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Scale", nil, "Failure preparing request") - return - } - - result, err = c.senderForScale(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Scale", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// ScaleThenPoll performs Scale then polls until it's completed -func (c StreamingJobsClient) ScaleThenPoll(ctx context.Context, id StreamingJobId, input ScaleStreamingJobParameters) error { - result, err := c.Scale(ctx, id, input) - if err != nil { - return fmt.Errorf("performing Scale: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Scale: %+v", err) - } - - return nil -} - -// preparerForScale prepares the Scale request. -func (c StreamingJobsClient) preparerForScale(ctx context.Context, id StreamingJobId, input ScaleStreamingJobParameters) (*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/scale", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForScale sends the Scale request. The method will close the -// http.Response Body if it receives an error. -func (c StreamingJobsClient) senderForScale(ctx context.Context, req *http.Request) (future ScaleOperationResponse, 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/streamanalytics/2020-03-01/streamingjobs/method_start.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_start.go new file mode 100644 index 00000000000..9ac7656ae02 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_start.go @@ -0,0 +1,74 @@ +package streamingjobs + +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 StartOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Start ... +func (c StreamingJobsClient) Start(ctx context.Context, id StreamingJobId, input StartStreamingJobParameters) (result StartOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/start", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// StartThenPoll performs Start then polls until it's completed +func (c StreamingJobsClient) StartThenPoll(ctx context.Context, id StreamingJobId, input StartStreamingJobParameters) error { + result, err := c.Start(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Start: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Start: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_start_autorest.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_start_autorest.go deleted file mode 100644 index eb10a45f098..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_start_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package streamingjobs - -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 StartOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// Start ... -func (c StreamingJobsClient) Start(ctx context.Context, id StreamingJobId, input StartStreamingJobParameters) (result StartOperationResponse, err error) { - req, err := c.preparerForStart(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Start", nil, "Failure preparing request") - return - } - - result, err = c.senderForStart(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Start", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// StartThenPoll performs Start then polls until it's completed -func (c StreamingJobsClient) StartThenPoll(ctx context.Context, id StreamingJobId, input StartStreamingJobParameters) error { - result, err := c.Start(ctx, id, input) - if err != nil { - return fmt.Errorf("performing Start: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Start: %+v", err) - } - - return nil -} - -// preparerForStart prepares the Start request. -func (c StreamingJobsClient) preparerForStart(ctx context.Context, id StreamingJobId, input StartStreamingJobParameters) (*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/start", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForStart sends the Start request. The method will close the -// http.Response Body if it receives an error. -func (c StreamingJobsClient) senderForStart(ctx context.Context, req *http.Request) (future StartOperationResponse, 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/streamanalytics/2020-03-01/streamingjobs/method_stop.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_stop.go new file mode 100644 index 00000000000..b4c00370cbe --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_stop.go @@ -0,0 +1,70 @@ +package streamingjobs + +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 StopOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Stop ... +func (c StreamingJobsClient) Stop(ctx context.Context, id StreamingJobId) (result StopOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/stop", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + 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 +} + +// StopThenPoll performs Stop then polls until it's completed +func (c StreamingJobsClient) StopThenPoll(ctx context.Context, id StreamingJobId) error { + result, err := c.Stop(ctx, id) + if err != nil { + return fmt.Errorf("performing Stop: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Stop: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_stop_autorest.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_stop_autorest.go deleted file mode 100644 index 1203d28307a..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_stop_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package streamingjobs - -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 StopOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// Stop ... -func (c StreamingJobsClient) Stop(ctx context.Context, id StreamingJobId) (result StopOperationResponse, err error) { - req, err := c.preparerForStop(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Stop", nil, "Failure preparing request") - return - } - - result, err = c.senderForStop(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Stop", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// StopThenPoll performs Stop then polls until it's completed -func (c StreamingJobsClient) StopThenPoll(ctx context.Context, id StreamingJobId) error { - result, err := c.Stop(ctx, id) - if err != nil { - return fmt.Errorf("performing Stop: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Stop: %+v", err) - } - - return nil -} - -// preparerForStop prepares the Stop request. -func (c StreamingJobsClient) preparerForStop(ctx context.Context, id StreamingJobId) (*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/stop", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForStop sends the Stop request. The method will close the -// http.Response Body if it receives an error. -func (c StreamingJobsClient) senderForStop(ctx context.Context, req *http.Request) (future StopOperationResponse, 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/streamanalytics/2020-03-01/streamingjobs/method_update.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_update.go new file mode 100644 index 00000000000..fd85377e1be --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_update.go @@ -0,0 +1,84 @@ +package streamingjobs + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StreamingJob +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c StreamingJobsClient) Update(ctx context.Context, id StreamingJobId, input StreamingJob, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2020-03-01/streamingjobs/method_update_autorest.go b/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_update_autorest.go deleted file mode 100644 index 863564082e1..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/streamingjobs/method_update_autorest.go +++ /dev/null @@ -1,98 +0,0 @@ -package streamingjobs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *StreamingJob -} - -type UpdateOperationOptions struct { - IfMatch *string -} - -func DefaultUpdateOperationOptions() UpdateOperationOptions { - return UpdateOperationOptions{} -} - -func (o UpdateOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - return out -} - -func (o UpdateOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// Update ... -func (c StreamingJobsClient) Update(ctx context.Context, id StreamingJobId, input StreamingJob, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c StreamingJobsClient) preparerForUpdate(ctx context.Context, id StreamingJobId, input StreamingJob, options UpdateOperationOptions) (*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.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - 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 StreamingJobsClient) 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/streamanalytics/2020-03-01/subscriptions/client.go b/resource-manager/streamanalytics/2020-03-01/subscriptions/client.go index da1257d5d97..09be7cb1cfb 100644 --- a/resource-manager/streamanalytics/2020-03-01/subscriptions/client.go +++ b/resource-manager/streamanalytics/2020-03-01/subscriptions/client.go @@ -1,18 +1,26 @@ package subscriptions -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 SubscriptionsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSubscriptionsClientWithBaseURI(endpoint string) SubscriptionsClient { - return SubscriptionsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSubscriptionsClientWithBaseURI(sdkApi sdkEnv.Api) (*SubscriptionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "subscriptions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SubscriptionsClient: %+v", err) } + + return &SubscriptionsClient{ + Client: client, + }, nil } diff --git a/resource-manager/streamanalytics/2020-03-01/subscriptions/method_listquotas.go b/resource-manager/streamanalytics/2020-03-01/subscriptions/method_listquotas.go new file mode 100644 index 00000000000..b0ec5d03882 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/subscriptions/method_listquotas.go @@ -0,0 +1,52 @@ +package subscriptions + +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 ListQuotasOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SubscriptionQuotasListResult +} + +// ListQuotas ... +func (c SubscriptionsClient) ListQuotas(ctx context.Context, id LocationId) (result ListQuotasOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/quotas", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + 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/streamanalytics/2020-03-01/subscriptions/method_listquotas_autorest.go b/resource-manager/streamanalytics/2020-03-01/subscriptions/method_listquotas_autorest.go deleted file mode 100644 index ef8e03ebb23..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/subscriptions/method_listquotas_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package subscriptions - -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 ListQuotasOperationResponse struct { - HttpResponse *http.Response - Model *SubscriptionQuotasListResult -} - -// ListQuotas ... -func (c SubscriptionsClient) ListQuotas(ctx context.Context, id LocationId) (result ListQuotasOperationResponse, err error) { - req, err := c.preparerForListQuotas(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "ListQuotas", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "ListQuotas", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListQuotas(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "ListQuotas", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForListQuotas prepares the ListQuotas request. -func (c SubscriptionsClient) preparerForListQuotas(ctx context.Context, id LocationId) (*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/quotas", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListQuotas handles the response to the ListQuotas request. The method always -// closes the http.Response Body. -func (c SubscriptionsClient) responderForListQuotas(resp *http.Response) (result ListQuotasOperationResponse, 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/streamanalytics/2020-03-01/transformations/client.go b/resource-manager/streamanalytics/2020-03-01/transformations/client.go index c2c425400f1..6808261e8bd 100644 --- a/resource-manager/streamanalytics/2020-03-01/transformations/client.go +++ b/resource-manager/streamanalytics/2020-03-01/transformations/client.go @@ -1,18 +1,26 @@ package transformations -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 TransformationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewTransformationsClientWithBaseURI(endpoint string) TransformationsClient { - return TransformationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewTransformationsClientWithBaseURI(sdkApi sdkEnv.Api) (*TransformationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "transformations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TransformationsClient: %+v", err) } + + return &TransformationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/streamanalytics/2020-03-01/transformations/method_createorreplace.go b/resource-manager/streamanalytics/2020-03-01/transformations/method_createorreplace.go new file mode 100644 index 00000000000..1a1320949ef --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/transformations/method_createorreplace.go @@ -0,0 +1,89 @@ +package transformations + +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 CreateOrReplaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Transformation +} + +type CreateOrReplaceOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { + return CreateOrReplaceOperationOptions{} +} + +func (o CreateOrReplaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrReplaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrReplaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrReplace ... +func (c TransformationsClient) CreateOrReplace(ctx context.Context, id TransformationId, input Transformation, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2020-03-01/transformations/method_createorreplace_autorest.go b/resource-manager/streamanalytics/2020-03-01/transformations/method_createorreplace_autorest.go deleted file mode 100644 index aec7a546815..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/transformations/method_createorreplace_autorest.go +++ /dev/null @@ -1,103 +0,0 @@ -package transformations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrReplaceOperationResponse struct { - HttpResponse *http.Response - Model *Transformation -} - -type CreateOrReplaceOperationOptions struct { - IfMatch *string - IfNoneMatch *string -} - -func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { - return CreateOrReplaceOperationOptions{} -} - -func (o CreateOrReplaceOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - if o.IfNoneMatch != nil { - out["If-None-Match"] = *o.IfNoneMatch - } - - return out -} - -func (o CreateOrReplaceOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// CreateOrReplace ... -func (c TransformationsClient) CreateOrReplace(ctx context.Context, id TransformationId, input Transformation, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { - req, err := c.preparerForCreateOrReplace(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "CreateOrReplace", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "CreateOrReplace", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrReplace(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "CreateOrReplace", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrReplace prepares the CreateOrReplace request. -func (c TransformationsClient) preparerForCreateOrReplace(ctx context.Context, id TransformationId, input Transformation, options CreateOrReplaceOperationOptions) (*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.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrReplace handles the response to the CreateOrReplace request. The method always -// closes the http.Response Body. -func (c TransformationsClient) responderForCreateOrReplace(resp *http.Response) (result CreateOrReplaceOperationResponse, 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/streamanalytics/2020-03-01/transformations/method_get.go b/resource-manager/streamanalytics/2020-03-01/transformations/method_get.go new file mode 100644 index 00000000000..339677722dd --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/transformations/method_get.go @@ -0,0 +1,51 @@ +package transformations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Transformation +} + +// Get ... +func (c TransformationsClient) Get(ctx context.Context, id TransformationId) (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/streamanalytics/2020-03-01/transformations/method_get_autorest.go b/resource-manager/streamanalytics/2020-03-01/transformations/method_get_autorest.go deleted file mode 100644 index d8ebe853c6a..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/transformations/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package transformations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Transformation -} - -// Get ... -func (c TransformationsClient) Get(ctx context.Context, id TransformationId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c TransformationsClient) preparerForGet(ctx context.Context, id TransformationId) (*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 TransformationsClient) 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/streamanalytics/2020-03-01/transformations/method_update.go b/resource-manager/streamanalytics/2020-03-01/transformations/method_update.go new file mode 100644 index 00000000000..3bf38dabf14 --- /dev/null +++ b/resource-manager/streamanalytics/2020-03-01/transformations/method_update.go @@ -0,0 +1,84 @@ +package transformations + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Transformation +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c TransformationsClient) Update(ctx context.Context, id TransformationId, input Transformation, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2020-03-01/transformations/method_update_autorest.go b/resource-manager/streamanalytics/2020-03-01/transformations/method_update_autorest.go deleted file mode 100644 index a5d5ea20798..00000000000 --- a/resource-manager/streamanalytics/2020-03-01/transformations/method_update_autorest.go +++ /dev/null @@ -1,98 +0,0 @@ -package transformations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Transformation -} - -type UpdateOperationOptions struct { - IfMatch *string -} - -func DefaultUpdateOperationOptions() UpdateOperationOptions { - return UpdateOperationOptions{} -} - -func (o UpdateOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - return out -} - -func (o UpdateOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// Update ... -func (c TransformationsClient) Update(ctx context.Context, id TransformationId, input Transformation, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c TransformationsClient) preparerForUpdate(ctx context.Context, id TransformationId, input Transformation, options UpdateOperationOptions) (*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.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - 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 TransformationsClient) 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/streamanalytics/2021-10-01-preview/client.go b/resource-manager/streamanalytics/2021-10-01-preview/client.go index fc92e660207..5a465899cf2 100644 --- a/resource-manager/streamanalytics/2021-10-01-preview/client.go +++ b/resource-manager/streamanalytics/2021-10-01-preview/client.go @@ -4,13 +4,16 @@ package v2021_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/streamanalytics/2021-10-01-preview/functions" "github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2021-10-01-preview/inputs" "github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2021-10-01-preview/outputs" "github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs" "github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2021-10-01-preview/subscriptions" "github.com/hashicorp/go-azure-sdk/resource-manager/streamanalytics/2021-10-01-preview/transformations" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" ) type Client struct { @@ -22,32 +25,49 @@ type Client struct { Transformations *transformations.TransformationsClient } -func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { - - functionsClient := functions.NewFunctionsClientWithBaseURI(endpoint) - configureAuthFunc(&functionsClient.Client) - - inputsClient := inputs.NewInputsClientWithBaseURI(endpoint) - configureAuthFunc(&inputsClient.Client) +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + functionsClient, err := functions.NewFunctionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Functions client: %+v", err) + } + configureFunc(functionsClient.Client) - outputsClient := outputs.NewOutputsClientWithBaseURI(endpoint) - configureAuthFunc(&outputsClient.Client) + inputsClient, err := inputs.NewInputsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Inputs client: %+v", err) + } + configureFunc(inputsClient.Client) - streamingJobsClient := streamingjobs.NewStreamingJobsClientWithBaseURI(endpoint) - configureAuthFunc(&streamingJobsClient.Client) + outputsClient, err := outputs.NewOutputsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Outputs client: %+v", err) + } + configureFunc(outputsClient.Client) - subscriptionsClient := subscriptions.NewSubscriptionsClientWithBaseURI(endpoint) - configureAuthFunc(&subscriptionsClient.Client) + streamingJobsClient, err := streamingjobs.NewStreamingJobsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building StreamingJobs client: %+v", err) + } + configureFunc(streamingJobsClient.Client) - transformationsClient := transformations.NewTransformationsClientWithBaseURI(endpoint) - configureAuthFunc(&transformationsClient.Client) + subscriptionsClient, err := subscriptions.NewSubscriptionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Subscriptions client: %+v", err) + } + configureFunc(subscriptionsClient.Client) - return Client{ - Functions: &functionsClient, - Inputs: &inputsClient, - Outputs: &outputsClient, - StreamingJobs: &streamingJobsClient, - Subscriptions: &subscriptionsClient, - Transformations: &transformationsClient, + transformationsClient, err := transformations.NewTransformationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Transformations client: %+v", err) } + configureFunc(transformationsClient.Client) + + return &Client{ + Functions: functionsClient, + Inputs: inputsClient, + Outputs: outputsClient, + StreamingJobs: streamingJobsClient, + Subscriptions: subscriptionsClient, + Transformations: transformationsClient, + }, nil } diff --git a/resource-manager/streamanalytics/2021-10-01-preview/functions/client.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/client.go index d8478486d96..07fdb1da32c 100644 --- a/resource-manager/streamanalytics/2021-10-01-preview/functions/client.go +++ b/resource-manager/streamanalytics/2021-10-01-preview/functions/client.go @@ -1,18 +1,26 @@ package functions -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 FunctionsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewFunctionsClientWithBaseURI(endpoint string) FunctionsClient { - return FunctionsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewFunctionsClientWithBaseURI(sdkApi sdkEnv.Api) (*FunctionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "functions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating FunctionsClient: %+v", err) } + + return &FunctionsClient{ + Client: client, + }, nil } diff --git a/resource-manager/streamanalytics/2021-10-01-preview/functions/constants.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/constants.go index 6cb63f908ac..9516e82c4f4 100644 --- a/resource-manager/streamanalytics/2021-10-01-preview/functions/constants.go +++ b/resource-manager/streamanalytics/2021-10-01-preview/functions/constants.go @@ -1,6 +1,10 @@ package functions -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 PossibleValuesForUdfType() []string { } } +func (s *UdfType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUdfType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseUdfType(input string) (*UdfType, error) { vals := map[string]UdfType{ "scalar": UdfTypeScalar, @@ -44,6 +61,19 @@ func PossibleValuesForUpdateMode() []string { } } +func (s *UpdateMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUpdateMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseUpdateMode(input string) (*UpdateMode, error) { vals := map[string]UpdateMode{ "refreshable": UpdateModeRefreshable, diff --git a/resource-manager/streamanalytics/2021-10-01-preview/functions/method_createorreplace.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_createorreplace.go new file mode 100644 index 00000000000..022771aa3df --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_createorreplace.go @@ -0,0 +1,89 @@ +package functions + +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 CreateOrReplaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Function +} + +type CreateOrReplaceOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { + return CreateOrReplaceOperationOptions{} +} + +func (o CreateOrReplaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrReplaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrReplaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrReplace ... +func (c FunctionsClient) CreateOrReplace(ctx context.Context, id FunctionId, input Function, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2021-10-01-preview/functions/method_createorreplace_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_createorreplace_autorest.go deleted file mode 100644 index 96bd230c74e..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/functions/method_createorreplace_autorest.go +++ /dev/null @@ -1,103 +0,0 @@ -package functions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrReplaceOperationResponse struct { - HttpResponse *http.Response - Model *Function -} - -type CreateOrReplaceOperationOptions struct { - IfMatch *string - IfNoneMatch *string -} - -func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { - return CreateOrReplaceOperationOptions{} -} - -func (o CreateOrReplaceOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - if o.IfNoneMatch != nil { - out["If-None-Match"] = *o.IfNoneMatch - } - - return out -} - -func (o CreateOrReplaceOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// CreateOrReplace ... -func (c FunctionsClient) CreateOrReplace(ctx context.Context, id FunctionId, input Function, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { - req, err := c.preparerForCreateOrReplace(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "CreateOrReplace", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "CreateOrReplace", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrReplace(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "CreateOrReplace", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrReplace prepares the CreateOrReplace request. -func (c FunctionsClient) preparerForCreateOrReplace(ctx context.Context, id FunctionId, input Function, options CreateOrReplaceOperationOptions) (*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.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrReplace handles the response to the CreateOrReplace request. The method always -// closes the http.Response Body. -func (c FunctionsClient) responderForCreateOrReplace(resp *http.Response) (result CreateOrReplaceOperationResponse, 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/streamanalytics/2021-10-01-preview/functions/method_delete.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_delete.go new file mode 100644 index 00000000000..9332b8f72c8 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_delete.go @@ -0,0 +1,47 @@ +package functions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 FunctionsClient) Delete(ctx context.Context, id FunctionId) (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/streamanalytics/2021-10-01-preview/functions/method_delete_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_delete_autorest.go deleted file mode 100644 index 460f6ac3da9..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/functions/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package functions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 FunctionsClient) Delete(ctx context.Context, id FunctionId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c FunctionsClient) preparerForDelete(ctx context.Context, id FunctionId) (*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 FunctionsClient) 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/streamanalytics/2021-10-01-preview/functions/method_get.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_get.go new file mode 100644 index 00000000000..8fe532bc9c6 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_get.go @@ -0,0 +1,51 @@ +package functions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Function +} + +// Get ... +func (c FunctionsClient) Get(ctx context.Context, id FunctionId) (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/streamanalytics/2021-10-01-preview/functions/method_get_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_get_autorest.go deleted file mode 100644 index b531eff94b5..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/functions/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package functions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Function -} - -// Get ... -func (c FunctionsClient) Get(ctx context.Context, id FunctionId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c FunctionsClient) preparerForGet(ctx context.Context, id FunctionId) (*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 FunctionsClient) 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/streamanalytics/2021-10-01-preview/functions/method_listbystreamingjob.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_listbystreamingjob.go new file mode 100644 index 00000000000..690bfe011ed --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_listbystreamingjob.go @@ -0,0 +1,119 @@ +package functions + +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 ListByStreamingJobOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Function +} + +type ListByStreamingJobCompleteResult struct { + LatestHttpResponse *http.Response + Items []Function +} + +type ListByStreamingJobOperationOptions struct { + Select *string +} + +func DefaultListByStreamingJobOperationOptions() ListByStreamingJobOperationOptions { + return ListByStreamingJobOperationOptions{} +} + +func (o ListByStreamingJobOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByStreamingJobOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByStreamingJobOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Select != nil { + out.Append("$select", fmt.Sprintf("%v", *o.Select)) + } + return &out +} + +// ListByStreamingJob ... +func (c FunctionsClient) ListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (result ListByStreamingJobOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/functions", 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 *[]Function `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByStreamingJobComplete retrieves all the results into a single object +func (c FunctionsClient) ListByStreamingJobComplete(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (ListByStreamingJobCompleteResult, error) { + return c.ListByStreamingJobCompleteMatchingPredicate(ctx, id, options, FunctionOperationPredicate{}) +} + +// ListByStreamingJobCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FunctionsClient) ListByStreamingJobCompleteMatchingPredicate(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions, predicate FunctionOperationPredicate) (result ListByStreamingJobCompleteResult, err error) { + items := make([]Function, 0) + + resp, err := c.ListByStreamingJob(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 = ListByStreamingJobCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/functions/method_listbystreamingjob_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_listbystreamingjob_autorest.go deleted file mode 100644 index 2f3271a3c78..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/functions/method_listbystreamingjob_autorest.go +++ /dev/null @@ -1,215 +0,0 @@ -package functions - -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 ListByStreamingJobOperationResponse struct { - HttpResponse *http.Response - Model *[]Function - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByStreamingJobOperationResponse, error) -} - -type ListByStreamingJobCompleteResult struct { - Items []Function -} - -func (r ListByStreamingJobOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByStreamingJobOperationResponse) LoadMore(ctx context.Context) (resp ListByStreamingJobOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListByStreamingJobOperationOptions struct { - Select *string -} - -func DefaultListByStreamingJobOperationOptions() ListByStreamingJobOperationOptions { - return ListByStreamingJobOperationOptions{} -} - -func (o ListByStreamingJobOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListByStreamingJobOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Select != nil { - out["$select"] = *o.Select - } - - return out -} - -// ListByStreamingJob ... -func (c FunctionsClient) ListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (resp ListByStreamingJobOperationResponse, err error) { - req, err := c.preparerForListByStreamingJob(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "ListByStreamingJob", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "ListByStreamingJob", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByStreamingJob(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "ListByStreamingJob", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByStreamingJob prepares the ListByStreamingJob request. -func (c FunctionsClient) preparerForListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (*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/functions", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByStreamingJobWithNextLink prepares the ListByStreamingJob request with the given nextLink token. -func (c FunctionsClient) preparerForListByStreamingJobWithNextLink(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)) -} - -// responderForListByStreamingJob handles the response to the ListByStreamingJob request. The method always -// closes the http.Response Body. -func (c FunctionsClient) responderForListByStreamingJob(resp *http.Response) (result ListByStreamingJobOperationResponse, err error) { - type page struct { - Values []Function `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 ListByStreamingJobOperationResponse, err error) { - req, err := c.preparerForListByStreamingJobWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "ListByStreamingJob", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "ListByStreamingJob", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByStreamingJob(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "ListByStreamingJob", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByStreamingJobComplete retrieves all of the results into a single object -func (c FunctionsClient) ListByStreamingJobComplete(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (ListByStreamingJobCompleteResult, error) { - return c.ListByStreamingJobCompleteMatchingPredicate(ctx, id, options, FunctionOperationPredicate{}) -} - -// ListByStreamingJobCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c FunctionsClient) ListByStreamingJobCompleteMatchingPredicate(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions, predicate FunctionOperationPredicate) (resp ListByStreamingJobCompleteResult, err error) { - items := make([]Function, 0) - - page, err := c.ListByStreamingJob(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 := ListByStreamingJobCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/functions/method_retrievedefaultdefinition.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_retrievedefaultdefinition.go new file mode 100644 index 00000000000..0b5970fbb25 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_retrievedefaultdefinition.go @@ -0,0 +1,56 @@ +package functions + +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 RetrieveDefaultDefinitionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Function +} + +// RetrieveDefaultDefinition ... +func (c FunctionsClient) RetrieveDefaultDefinition(ctx context.Context, id FunctionId, input FunctionRetrieveDefaultDefinitionParameters) (result RetrieveDefaultDefinitionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/retrieveDefaultDefinition", 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/streamanalytics/2021-10-01-preview/functions/method_retrievedefaultdefinition_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_retrievedefaultdefinition_autorest.go deleted file mode 100644 index 3be1fb89bd6..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/functions/method_retrievedefaultdefinition_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package functions - -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 RetrieveDefaultDefinitionOperationResponse struct { - HttpResponse *http.Response - Model *Function -} - -// RetrieveDefaultDefinition ... -func (c FunctionsClient) RetrieveDefaultDefinition(ctx context.Context, id FunctionId, input FunctionRetrieveDefaultDefinitionParameters) (result RetrieveDefaultDefinitionOperationResponse, err error) { - req, err := c.preparerForRetrieveDefaultDefinition(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "RetrieveDefaultDefinition", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "RetrieveDefaultDefinition", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForRetrieveDefaultDefinition(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "RetrieveDefaultDefinition", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForRetrieveDefaultDefinition prepares the RetrieveDefaultDefinition request. -func (c FunctionsClient) preparerForRetrieveDefaultDefinition(ctx context.Context, id FunctionId, input FunctionRetrieveDefaultDefinitionParameters) (*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/retrieveDefaultDefinition", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForRetrieveDefaultDefinition handles the response to the RetrieveDefaultDefinition request. The method always -// closes the http.Response Body. -func (c FunctionsClient) responderForRetrieveDefaultDefinition(resp *http.Response) (result RetrieveDefaultDefinitionOperationResponse, 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/streamanalytics/2021-10-01-preview/functions/method_test.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_test.go new file mode 100644 index 00000000000..f50d7238966 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_test.go @@ -0,0 +1,75 @@ +package functions + +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 TestOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ResourceTestStatus +} + +// Test ... +func (c FunctionsClient) Test(ctx context.Context, id FunctionId, input Function) (result TestOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/test", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// TestThenPoll performs Test then polls until it's completed +func (c FunctionsClient) TestThenPoll(ctx context.Context, id FunctionId, input Function) error { + result, err := c.Test(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Test: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Test: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/functions/method_test_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_test_autorest.go deleted file mode 100644 index 40c3044f720..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/functions/method_test_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package functions - -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 TestOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *ResourceTestStatus -} - -// Test ... -func (c FunctionsClient) Test(ctx context.Context, id FunctionId, input Function) (result TestOperationResponse, err error) { - req, err := c.preparerForTest(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Test", nil, "Failure preparing request") - return - } - - result, err = c.senderForTest(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Test", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// TestThenPoll performs Test then polls until it's completed -func (c FunctionsClient) TestThenPoll(ctx context.Context, id FunctionId, input Function) error { - result, err := c.Test(ctx, id, input) - if err != nil { - return fmt.Errorf("performing Test: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Test: %+v", err) - } - - return nil -} - -// preparerForTest prepares the Test request. -func (c FunctionsClient) preparerForTest(ctx context.Context, id FunctionId, input Function) (*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/test", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForTest sends the Test request. The method will close the -// http.Response Body if it receives an error. -func (c FunctionsClient) senderForTest(ctx context.Context, req *http.Request) (future TestOperationResponse, 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/streamanalytics/2021-10-01-preview/functions/method_update.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_update.go new file mode 100644 index 00000000000..af905ccf9c8 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_update.go @@ -0,0 +1,84 @@ +package functions + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Function +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c FunctionsClient) Update(ctx context.Context, id FunctionId, input Function, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2021-10-01-preview/functions/method_update_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/functions/method_update_autorest.go deleted file mode 100644 index 07b0dd63c19..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/functions/method_update_autorest.go +++ /dev/null @@ -1,98 +0,0 @@ -package functions - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Function -} - -type UpdateOperationOptions struct { - IfMatch *string -} - -func DefaultUpdateOperationOptions() UpdateOperationOptions { - return UpdateOperationOptions{} -} - -func (o UpdateOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - return out -} - -func (o UpdateOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// Update ... -func (c FunctionsClient) Update(ctx context.Context, id FunctionId, input Function, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "functions.FunctionsClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c FunctionsClient) preparerForUpdate(ctx context.Context, id FunctionId, input Function, options UpdateOperationOptions) (*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.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - 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 FunctionsClient) 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/streamanalytics/2021-10-01-preview/inputs/client.go b/resource-manager/streamanalytics/2021-10-01-preview/inputs/client.go index 859c2802c38..fa5493aa37f 100644 --- a/resource-manager/streamanalytics/2021-10-01-preview/inputs/client.go +++ b/resource-manager/streamanalytics/2021-10-01-preview/inputs/client.go @@ -1,18 +1,26 @@ package inputs -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 InputsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewInputsClientWithBaseURI(endpoint string) InputsClient { - return InputsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewInputsClientWithBaseURI(sdkApi sdkEnv.Api) (*InputsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "inputs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating InputsClient: %+v", err) } + + return &InputsClient{ + Client: client, + }, nil } diff --git a/resource-manager/streamanalytics/2021-10-01-preview/inputs/constants.go b/resource-manager/streamanalytics/2021-10-01-preview/inputs/constants.go index f509d4c62a6..1edabb85e3d 100644 --- a/resource-manager/streamanalytics/2021-10-01-preview/inputs/constants.go +++ b/resource-manager/streamanalytics/2021-10-01-preview/inputs/constants.go @@ -1,6 +1,10 @@ package inputs -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 PossibleValuesForAuthenticationMode() []string { } } +func (s *AuthenticationMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAuthenticationMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAuthenticationMode(input string) (*AuthenticationMode, error) { vals := map[string]AuthenticationMode{ "connectionstring": AuthenticationModeConnectionString, @@ -52,6 +69,19 @@ func PossibleValuesForCompressionType() []string { } } +func (s *CompressionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCompressionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCompressionType(input string) (*CompressionType, error) { vals := map[string]CompressionType{ "deflate": CompressionTypeDeflate, @@ -79,6 +109,19 @@ func PossibleValuesForEncoding() []string { } } +func (s *Encoding) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEncoding(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEncoding(input string) (*Encoding, error) { vals := map[string]Encoding{ "utf8": EncodingUTFEight, @@ -106,6 +149,19 @@ func PossibleValuesForEventGridEventSchemaType() []string { } } +func (s *EventGridEventSchemaType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGridEventSchemaType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGridEventSchemaType(input string) (*EventGridEventSchemaType, error) { vals := map[string]EventGridEventSchemaType{ "cloudeventschema": EventGridEventSchemaTypeCloudEventSchema, @@ -142,6 +198,19 @@ func PossibleValuesForEventSerializationType() []string { } } +func (s *EventSerializationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventSerializationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventSerializationType(input string) (*EventSerializationType, error) { vals := map[string]EventSerializationType{ "avro": EventSerializationTypeAvro, @@ -174,6 +243,19 @@ func PossibleValuesForInputWatermarkMode() []string { } } +func (s *InputWatermarkMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseInputWatermarkMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseInputWatermarkMode(input string) (*InputWatermarkMode, error) { vals := map[string]InputWatermarkMode{ "none": InputWatermarkModeNone, @@ -202,6 +284,19 @@ func PossibleValuesForJsonOutputSerializationFormat() []string { } } +func (s *JsonOutputSerializationFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJsonOutputSerializationFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseJsonOutputSerializationFormat(input string) (*JsonOutputSerializationFormat, error) { vals := map[string]JsonOutputSerializationFormat{ "array": JsonOutputSerializationFormatArray, @@ -232,6 +327,19 @@ func PossibleValuesForRefreshType() []string { } } +func (s *RefreshType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRefreshType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRefreshType(input string) (*RefreshType, error) { vals := map[string]RefreshType{ "refreshperiodicallywithdelta": RefreshTypeRefreshPeriodicallyWithDelta, diff --git a/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_createorreplace.go b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_createorreplace.go new file mode 100644 index 00000000000..6337031f48a --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_createorreplace.go @@ -0,0 +1,89 @@ +package inputs + +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 CreateOrReplaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Input +} + +type CreateOrReplaceOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { + return CreateOrReplaceOperationOptions{} +} + +func (o CreateOrReplaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrReplaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrReplaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrReplace ... +func (c InputsClient) CreateOrReplace(ctx context.Context, id InputId, input Input, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2021-10-01-preview/inputs/method_createorreplace_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_createorreplace_autorest.go deleted file mode 100644 index ea3a65c3426..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_createorreplace_autorest.go +++ /dev/null @@ -1,103 +0,0 @@ -package inputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrReplaceOperationResponse struct { - HttpResponse *http.Response - Model *Input -} - -type CreateOrReplaceOperationOptions struct { - IfMatch *string - IfNoneMatch *string -} - -func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { - return CreateOrReplaceOperationOptions{} -} - -func (o CreateOrReplaceOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - if o.IfNoneMatch != nil { - out["If-None-Match"] = *o.IfNoneMatch - } - - return out -} - -func (o CreateOrReplaceOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// CreateOrReplace ... -func (c InputsClient) CreateOrReplace(ctx context.Context, id InputId, input Input, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { - req, err := c.preparerForCreateOrReplace(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "CreateOrReplace", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "CreateOrReplace", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrReplace(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "CreateOrReplace", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrReplace prepares the CreateOrReplace request. -func (c InputsClient) preparerForCreateOrReplace(ctx context.Context, id InputId, input Input, options CreateOrReplaceOperationOptions) (*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.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrReplace handles the response to the CreateOrReplace request. The method always -// closes the http.Response Body. -func (c InputsClient) responderForCreateOrReplace(resp *http.Response) (result CreateOrReplaceOperationResponse, 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/streamanalytics/2021-10-01-preview/inputs/method_delete.go b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_delete.go new file mode 100644 index 00000000000..000c88164d1 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_delete.go @@ -0,0 +1,47 @@ +package inputs + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 InputsClient) Delete(ctx context.Context, id InputId) (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/streamanalytics/2021-10-01-preview/inputs/method_delete_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_delete_autorest.go deleted file mode 100644 index 0df6db9b503..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package inputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 InputsClient) Delete(ctx context.Context, id InputId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c InputsClient) preparerForDelete(ctx context.Context, id InputId) (*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 InputsClient) 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/streamanalytics/2021-10-01-preview/inputs/method_get.go b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_get.go new file mode 100644 index 00000000000..e108d651002 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_get.go @@ -0,0 +1,51 @@ +package inputs + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Input +} + +// Get ... +func (c InputsClient) Get(ctx context.Context, id InputId) (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/streamanalytics/2021-10-01-preview/inputs/method_get_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_get_autorest.go deleted file mode 100644 index bb6e886dfcb..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package inputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Input -} - -// Get ... -func (c InputsClient) Get(ctx context.Context, id InputId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c InputsClient) preparerForGet(ctx context.Context, id InputId) (*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 InputsClient) 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/streamanalytics/2021-10-01-preview/inputs/method_listbystreamingjob.go b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_listbystreamingjob.go new file mode 100644 index 00000000000..6fd6245baf2 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_listbystreamingjob.go @@ -0,0 +1,119 @@ +package inputs + +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 ListByStreamingJobOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Input +} + +type ListByStreamingJobCompleteResult struct { + LatestHttpResponse *http.Response + Items []Input +} + +type ListByStreamingJobOperationOptions struct { + Select *string +} + +func DefaultListByStreamingJobOperationOptions() ListByStreamingJobOperationOptions { + return ListByStreamingJobOperationOptions{} +} + +func (o ListByStreamingJobOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByStreamingJobOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByStreamingJobOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Select != nil { + out.Append("$select", fmt.Sprintf("%v", *o.Select)) + } + return &out +} + +// ListByStreamingJob ... +func (c InputsClient) ListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (result ListByStreamingJobOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/inputs", 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 *[]Input `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByStreamingJobComplete retrieves all the results into a single object +func (c InputsClient) ListByStreamingJobComplete(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (ListByStreamingJobCompleteResult, error) { + return c.ListByStreamingJobCompleteMatchingPredicate(ctx, id, options, InputOperationPredicate{}) +} + +// ListByStreamingJobCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c InputsClient) ListByStreamingJobCompleteMatchingPredicate(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions, predicate InputOperationPredicate) (result ListByStreamingJobCompleteResult, err error) { + items := make([]Input, 0) + + resp, err := c.ListByStreamingJob(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 = ListByStreamingJobCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_listbystreamingjob_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_listbystreamingjob_autorest.go deleted file mode 100644 index a86ec923786..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_listbystreamingjob_autorest.go +++ /dev/null @@ -1,215 +0,0 @@ -package inputs - -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 ListByStreamingJobOperationResponse struct { - HttpResponse *http.Response - Model *[]Input - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByStreamingJobOperationResponse, error) -} - -type ListByStreamingJobCompleteResult struct { - Items []Input -} - -func (r ListByStreamingJobOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByStreamingJobOperationResponse) LoadMore(ctx context.Context) (resp ListByStreamingJobOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListByStreamingJobOperationOptions struct { - Select *string -} - -func DefaultListByStreamingJobOperationOptions() ListByStreamingJobOperationOptions { - return ListByStreamingJobOperationOptions{} -} - -func (o ListByStreamingJobOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListByStreamingJobOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Select != nil { - out["$select"] = *o.Select - } - - return out -} - -// ListByStreamingJob ... -func (c InputsClient) ListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (resp ListByStreamingJobOperationResponse, err error) { - req, err := c.preparerForListByStreamingJob(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "ListByStreamingJob", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "ListByStreamingJob", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByStreamingJob(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "ListByStreamingJob", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByStreamingJob prepares the ListByStreamingJob request. -func (c InputsClient) preparerForListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (*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/inputs", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByStreamingJobWithNextLink prepares the ListByStreamingJob request with the given nextLink token. -func (c InputsClient) preparerForListByStreamingJobWithNextLink(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)) -} - -// responderForListByStreamingJob handles the response to the ListByStreamingJob request. The method always -// closes the http.Response Body. -func (c InputsClient) responderForListByStreamingJob(resp *http.Response) (result ListByStreamingJobOperationResponse, err error) { - type page struct { - Values []Input `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 ListByStreamingJobOperationResponse, err error) { - req, err := c.preparerForListByStreamingJobWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "ListByStreamingJob", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "ListByStreamingJob", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByStreamingJob(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "ListByStreamingJob", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByStreamingJobComplete retrieves all of the results into a single object -func (c InputsClient) ListByStreamingJobComplete(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (ListByStreamingJobCompleteResult, error) { - return c.ListByStreamingJobCompleteMatchingPredicate(ctx, id, options, InputOperationPredicate{}) -} - -// ListByStreamingJobCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c InputsClient) ListByStreamingJobCompleteMatchingPredicate(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions, predicate InputOperationPredicate) (resp ListByStreamingJobCompleteResult, err error) { - items := make([]Input, 0) - - page, err := c.ListByStreamingJob(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 := ListByStreamingJobCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_test.go b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_test.go new file mode 100644 index 00000000000..6fff5988979 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_test.go @@ -0,0 +1,75 @@ +package inputs + +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 TestOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ResourceTestStatus +} + +// Test ... +func (c InputsClient) Test(ctx context.Context, id InputId, input Input) (result TestOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/test", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// TestThenPoll performs Test then polls until it's completed +func (c InputsClient) TestThenPoll(ctx context.Context, id InputId, input Input) error { + result, err := c.Test(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Test: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Test: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_test_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_test_autorest.go deleted file mode 100644 index ec55575caea..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_test_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package inputs - -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 TestOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *ResourceTestStatus -} - -// Test ... -func (c InputsClient) Test(ctx context.Context, id InputId, input Input) (result TestOperationResponse, err error) { - req, err := c.preparerForTest(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Test", nil, "Failure preparing request") - return - } - - result, err = c.senderForTest(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Test", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// TestThenPoll performs Test then polls until it's completed -func (c InputsClient) TestThenPoll(ctx context.Context, id InputId, input Input) error { - result, err := c.Test(ctx, id, input) - if err != nil { - return fmt.Errorf("performing Test: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Test: %+v", err) - } - - return nil -} - -// preparerForTest prepares the Test request. -func (c InputsClient) preparerForTest(ctx context.Context, id InputId, input Input) (*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/test", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForTest sends the Test request. The method will close the -// http.Response Body if it receives an error. -func (c InputsClient) senderForTest(ctx context.Context, req *http.Request) (future TestOperationResponse, 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/streamanalytics/2021-10-01-preview/inputs/method_update.go b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_update.go new file mode 100644 index 00000000000..8816b664425 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_update.go @@ -0,0 +1,84 @@ +package inputs + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Input +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c InputsClient) Update(ctx context.Context, id InputId, input Input, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2021-10-01-preview/inputs/method_update_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_update_autorest.go deleted file mode 100644 index a6e3027501a..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/inputs/method_update_autorest.go +++ /dev/null @@ -1,98 +0,0 @@ -package inputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Input -} - -type UpdateOperationOptions struct { - IfMatch *string -} - -func DefaultUpdateOperationOptions() UpdateOperationOptions { - return UpdateOperationOptions{} -} - -func (o UpdateOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - return out -} - -func (o UpdateOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// Update ... -func (c InputsClient) Update(ctx context.Context, id InputId, input Input, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "inputs.InputsClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c InputsClient) preparerForUpdate(ctx context.Context, id InputId, input Input, options UpdateOperationOptions) (*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.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - 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 InputsClient) 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/streamanalytics/2021-10-01-preview/outputs/client.go b/resource-manager/streamanalytics/2021-10-01-preview/outputs/client.go index 90cdaf9a2f3..a14d848cb27 100644 --- a/resource-manager/streamanalytics/2021-10-01-preview/outputs/client.go +++ b/resource-manager/streamanalytics/2021-10-01-preview/outputs/client.go @@ -1,18 +1,26 @@ package outputs -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 OutputsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewOutputsClientWithBaseURI(endpoint string) OutputsClient { - return OutputsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewOutputsClientWithBaseURI(sdkApi sdkEnv.Api) (*OutputsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "outputs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating OutputsClient: %+v", err) } + + return &OutputsClient{ + Client: client, + }, nil } diff --git a/resource-manager/streamanalytics/2021-10-01-preview/outputs/constants.go b/resource-manager/streamanalytics/2021-10-01-preview/outputs/constants.go index dea58756f7c..7fd79b0b908 100644 --- a/resource-manager/streamanalytics/2021-10-01-preview/outputs/constants.go +++ b/resource-manager/streamanalytics/2021-10-01-preview/outputs/constants.go @@ -1,6 +1,10 @@ package outputs -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 PossibleValuesForAuthenticationMode() []string { } } +func (s *AuthenticationMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAuthenticationMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAuthenticationMode(input string) (*AuthenticationMode, error) { vals := map[string]AuthenticationMode{ "connectionstring": AuthenticationModeConnectionString, @@ -50,6 +67,19 @@ func PossibleValuesForBlobWriteMode() []string { } } +func (s *BlobWriteMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBlobWriteMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseBlobWriteMode(input string) (*BlobWriteMode, error) { vals := map[string]BlobWriteMode{ "append": BlobWriteModeAppend, @@ -76,6 +106,19 @@ func PossibleValuesForEncoding() []string { } } +func (s *Encoding) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEncoding(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEncoding(input string) (*Encoding, error) { vals := map[string]Encoding{ "utf8": EncodingUTFEight, @@ -111,6 +154,19 @@ func PossibleValuesForEventSerializationType() []string { } } +func (s *EventSerializationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventSerializationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventSerializationType(input string) (*EventSerializationType, error) { vals := map[string]EventSerializationType{ "avro": EventSerializationTypeAvro, @@ -143,6 +199,19 @@ func PossibleValuesForJsonOutputSerializationFormat() []string { } } +func (s *JsonOutputSerializationFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJsonOutputSerializationFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseJsonOutputSerializationFormat(input string) (*JsonOutputSerializationFormat, error) { vals := map[string]JsonOutputSerializationFormat{ "array": JsonOutputSerializationFormatArray, @@ -173,6 +242,19 @@ func PossibleValuesForOutputWatermarkMode() []string { } } +func (s *OutputWatermarkMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOutputWatermarkMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOutputWatermarkMode(input string) (*OutputWatermarkMode, error) { vals := map[string]OutputWatermarkMode{ "none": OutputWatermarkModeNone, diff --git a/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_createorreplace.go b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_createorreplace.go new file mode 100644 index 00000000000..ca182b4586c --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_createorreplace.go @@ -0,0 +1,89 @@ +package outputs + +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 CreateOrReplaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Output +} + +type CreateOrReplaceOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { + return CreateOrReplaceOperationOptions{} +} + +func (o CreateOrReplaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrReplaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrReplaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrReplace ... +func (c OutputsClient) CreateOrReplace(ctx context.Context, id OutputId, input Output, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2021-10-01-preview/outputs/method_createorreplace_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_createorreplace_autorest.go deleted file mode 100644 index 4d25b5c5877..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_createorreplace_autorest.go +++ /dev/null @@ -1,103 +0,0 @@ -package outputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrReplaceOperationResponse struct { - HttpResponse *http.Response - Model *Output -} - -type CreateOrReplaceOperationOptions struct { - IfMatch *string - IfNoneMatch *string -} - -func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { - return CreateOrReplaceOperationOptions{} -} - -func (o CreateOrReplaceOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - if o.IfNoneMatch != nil { - out["If-None-Match"] = *o.IfNoneMatch - } - - return out -} - -func (o CreateOrReplaceOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// CreateOrReplace ... -func (c OutputsClient) CreateOrReplace(ctx context.Context, id OutputId, input Output, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { - req, err := c.preparerForCreateOrReplace(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "CreateOrReplace", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "CreateOrReplace", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrReplace(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "CreateOrReplace", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrReplace prepares the CreateOrReplace request. -func (c OutputsClient) preparerForCreateOrReplace(ctx context.Context, id OutputId, input Output, options CreateOrReplaceOperationOptions) (*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.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrReplace handles the response to the CreateOrReplace request. The method always -// closes the http.Response Body. -func (c OutputsClient) responderForCreateOrReplace(resp *http.Response) (result CreateOrReplaceOperationResponse, 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/streamanalytics/2021-10-01-preview/outputs/method_delete.go b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_delete.go new file mode 100644 index 00000000000..7abe427d104 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_delete.go @@ -0,0 +1,47 @@ +package outputs + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 OutputsClient) Delete(ctx context.Context, id OutputId) (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/streamanalytics/2021-10-01-preview/outputs/method_delete_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_delete_autorest.go deleted file mode 100644 index 9ba461f884f..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_delete_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package outputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 OutputsClient) Delete(ctx context.Context, id OutputId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Delete", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForDelete(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Delete", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForDelete prepares the Delete request. -func (c OutputsClient) preparerForDelete(ctx context.Context, id OutputId) (*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 OutputsClient) 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/streamanalytics/2021-10-01-preview/outputs/method_get.go b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_get.go new file mode 100644 index 00000000000..f0eee6a3d1c --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_get.go @@ -0,0 +1,51 @@ +package outputs + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Output +} + +// Get ... +func (c OutputsClient) Get(ctx context.Context, id OutputId) (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/streamanalytics/2021-10-01-preview/outputs/method_get_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_get_autorest.go deleted file mode 100644 index 11f1639925b..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package outputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Output -} - -// Get ... -func (c OutputsClient) Get(ctx context.Context, id OutputId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c OutputsClient) preparerForGet(ctx context.Context, id OutputId) (*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 OutputsClient) 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/streamanalytics/2021-10-01-preview/outputs/method_listbystreamingjob.go b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_listbystreamingjob.go new file mode 100644 index 00000000000..42acfe0a467 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_listbystreamingjob.go @@ -0,0 +1,119 @@ +package outputs + +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 ListByStreamingJobOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Output +} + +type ListByStreamingJobCompleteResult struct { + LatestHttpResponse *http.Response + Items []Output +} + +type ListByStreamingJobOperationOptions struct { + Select *string +} + +func DefaultListByStreamingJobOperationOptions() ListByStreamingJobOperationOptions { + return ListByStreamingJobOperationOptions{} +} + +func (o ListByStreamingJobOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByStreamingJobOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByStreamingJobOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Select != nil { + out.Append("$select", fmt.Sprintf("%v", *o.Select)) + } + return &out +} + +// ListByStreamingJob ... +func (c OutputsClient) ListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (result ListByStreamingJobOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/outputs", 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 *[]Output `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByStreamingJobComplete retrieves all the results into a single object +func (c OutputsClient) ListByStreamingJobComplete(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (ListByStreamingJobCompleteResult, error) { + return c.ListByStreamingJobCompleteMatchingPredicate(ctx, id, options, OutputOperationPredicate{}) +} + +// ListByStreamingJobCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c OutputsClient) ListByStreamingJobCompleteMatchingPredicate(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions, predicate OutputOperationPredicate) (result ListByStreamingJobCompleteResult, err error) { + items := make([]Output, 0) + + resp, err := c.ListByStreamingJob(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 = ListByStreamingJobCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_listbystreamingjob_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_listbystreamingjob_autorest.go deleted file mode 100644 index b0dae7269a0..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_listbystreamingjob_autorest.go +++ /dev/null @@ -1,215 +0,0 @@ -package outputs - -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 ListByStreamingJobOperationResponse struct { - HttpResponse *http.Response - Model *[]Output - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByStreamingJobOperationResponse, error) -} - -type ListByStreamingJobCompleteResult struct { - Items []Output -} - -func (r ListByStreamingJobOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByStreamingJobOperationResponse) LoadMore(ctx context.Context) (resp ListByStreamingJobOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListByStreamingJobOperationOptions struct { - Select *string -} - -func DefaultListByStreamingJobOperationOptions() ListByStreamingJobOperationOptions { - return ListByStreamingJobOperationOptions{} -} - -func (o ListByStreamingJobOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListByStreamingJobOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Select != nil { - out["$select"] = *o.Select - } - - return out -} - -// ListByStreamingJob ... -func (c OutputsClient) ListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (resp ListByStreamingJobOperationResponse, err error) { - req, err := c.preparerForListByStreamingJob(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "ListByStreamingJob", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "ListByStreamingJob", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByStreamingJob(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "ListByStreamingJob", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByStreamingJob prepares the ListByStreamingJob request. -func (c OutputsClient) preparerForListByStreamingJob(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (*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/outputs", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByStreamingJobWithNextLink prepares the ListByStreamingJob request with the given nextLink token. -func (c OutputsClient) preparerForListByStreamingJobWithNextLink(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)) -} - -// responderForListByStreamingJob handles the response to the ListByStreamingJob request. The method always -// closes the http.Response Body. -func (c OutputsClient) responderForListByStreamingJob(resp *http.Response) (result ListByStreamingJobOperationResponse, err error) { - type page struct { - Values []Output `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 ListByStreamingJobOperationResponse, err error) { - req, err := c.preparerForListByStreamingJobWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "ListByStreamingJob", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "ListByStreamingJob", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByStreamingJob(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "ListByStreamingJob", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByStreamingJobComplete retrieves all of the results into a single object -func (c OutputsClient) ListByStreamingJobComplete(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions) (ListByStreamingJobCompleteResult, error) { - return c.ListByStreamingJobCompleteMatchingPredicate(ctx, id, options, OutputOperationPredicate{}) -} - -// ListByStreamingJobCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c OutputsClient) ListByStreamingJobCompleteMatchingPredicate(ctx context.Context, id StreamingJobId, options ListByStreamingJobOperationOptions, predicate OutputOperationPredicate) (resp ListByStreamingJobCompleteResult, err error) { - items := make([]Output, 0) - - page, err := c.ListByStreamingJob(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 := ListByStreamingJobCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_test.go b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_test.go new file mode 100644 index 00000000000..7979047cc1d --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_test.go @@ -0,0 +1,75 @@ +package outputs + +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 TestOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ResourceTestStatus +} + +// Test ... +func (c OutputsClient) Test(ctx context.Context, id OutputId, input Output) (result TestOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/test", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// TestThenPoll performs Test then polls until it's completed +func (c OutputsClient) TestThenPoll(ctx context.Context, id OutputId, input Output) error { + result, err := c.Test(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Test: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Test: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_test_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_test_autorest.go deleted file mode 100644 index 0469b557cab..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_test_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package outputs - -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 TestOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *ResourceTestStatus -} - -// Test ... -func (c OutputsClient) Test(ctx context.Context, id OutputId, input Output) (result TestOperationResponse, err error) { - req, err := c.preparerForTest(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Test", nil, "Failure preparing request") - return - } - - result, err = c.senderForTest(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Test", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// TestThenPoll performs Test then polls until it's completed -func (c OutputsClient) TestThenPoll(ctx context.Context, id OutputId, input Output) error { - result, err := c.Test(ctx, id, input) - if err != nil { - return fmt.Errorf("performing Test: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Test: %+v", err) - } - - return nil -} - -// preparerForTest prepares the Test request. -func (c OutputsClient) preparerForTest(ctx context.Context, id OutputId, input Output) (*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/test", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForTest sends the Test request. The method will close the -// http.Response Body if it receives an error. -func (c OutputsClient) senderForTest(ctx context.Context, req *http.Request) (future TestOperationResponse, 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/streamanalytics/2021-10-01-preview/outputs/method_update.go b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_update.go new file mode 100644 index 00000000000..b373774238c --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_update.go @@ -0,0 +1,84 @@ +package outputs + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Output +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c OutputsClient) Update(ctx context.Context, id OutputId, input Output, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2021-10-01-preview/outputs/method_update_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_update_autorest.go deleted file mode 100644 index 6ca83b47aa9..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/outputs/method_update_autorest.go +++ /dev/null @@ -1,98 +0,0 @@ -package outputs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Output -} - -type UpdateOperationOptions struct { - IfMatch *string -} - -func DefaultUpdateOperationOptions() UpdateOperationOptions { - return UpdateOperationOptions{} -} - -func (o UpdateOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - return out -} - -func (o UpdateOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// Update ... -func (c OutputsClient) Update(ctx context.Context, id OutputId, input Output, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "outputs.OutputsClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c OutputsClient) preparerForUpdate(ctx context.Context, id OutputId, input Output, options UpdateOperationOptions) (*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.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - 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 OutputsClient) 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/streamanalytics/2021-10-01-preview/streamingjobs/client.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/client.go index 0e0a6976291..2e04ee218cc 100644 --- a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/client.go +++ b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/client.go @@ -1,18 +1,26 @@ package streamingjobs -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 StreamingJobsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewStreamingJobsClientWithBaseURI(endpoint string) StreamingJobsClient { - return StreamingJobsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewStreamingJobsClientWithBaseURI(sdkApi sdkEnv.Api) (*StreamingJobsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "streamingjobs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating StreamingJobsClient: %+v", err) } + + return &StreamingJobsClient{ + Client: client, + }, nil } diff --git a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/constants.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/constants.go index 73ce2c99b86..83546b40fdd 100644 --- a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/constants.go +++ b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/constants.go @@ -1,6 +1,10 @@ package streamingjobs -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 PossibleValuesForAuthenticationMode() []string { } } +func (s *AuthenticationMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAuthenticationMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAuthenticationMode(input string) (*AuthenticationMode, error) { vals := map[string]AuthenticationMode{ "connectionstring": AuthenticationModeConnectionString, @@ -50,6 +67,19 @@ func PossibleValuesForBlobWriteMode() []string { } } +func (s *BlobWriteMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBlobWriteMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseBlobWriteMode(input string) (*BlobWriteMode, error) { vals := map[string]BlobWriteMode{ "append": BlobWriteModeAppend, @@ -78,6 +108,19 @@ func PossibleValuesForCompatibilityLevel() []string { } } +func (s *CompatibilityLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCompatibilityLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCompatibilityLevel(input string) (*CompatibilityLevel, error) { vals := map[string]CompatibilityLevel{ "1.2": CompatibilityLevelOnePointTwo, @@ -108,6 +151,19 @@ func PossibleValuesForCompressionType() []string { } } +func (s *CompressionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCompressionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCompressionType(input string) (*CompressionType, error) { vals := map[string]CompressionType{ "deflate": CompressionTypeDeflate, @@ -137,6 +193,19 @@ func PossibleValuesForContentStoragePolicy() []string { } } +func (s *ContentStoragePolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContentStoragePolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseContentStoragePolicy(input string) (*ContentStoragePolicy, error) { vals := map[string]ContentStoragePolicy{ "jobstorageaccount": ContentStoragePolicyJobStorageAccount, @@ -163,6 +232,19 @@ func PossibleValuesForEncoding() []string { } } +func (s *Encoding) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEncoding(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEncoding(input string) (*Encoding, error) { vals := map[string]Encoding{ "utf8": EncodingUTFEight, @@ -190,6 +272,19 @@ func PossibleValuesForEventGridEventSchemaType() []string { } } +func (s *EventGridEventSchemaType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGridEventSchemaType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGridEventSchemaType(input string) (*EventGridEventSchemaType, error) { vals := map[string]EventGridEventSchemaType{ "cloudeventschema": EventGridEventSchemaTypeCloudEventSchema, @@ -226,6 +321,19 @@ func PossibleValuesForEventSerializationType() []string { } } +func (s *EventSerializationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventSerializationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventSerializationType(input string) (*EventSerializationType, error) { vals := map[string]EventSerializationType{ "avro": EventSerializationTypeAvro, @@ -258,6 +366,19 @@ func PossibleValuesForEventsOutOfOrderPolicy() []string { } } +func (s *EventsOutOfOrderPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventsOutOfOrderPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventsOutOfOrderPolicy(input string) (*EventsOutOfOrderPolicy, error) { vals := map[string]EventsOutOfOrderPolicy{ "adjust": EventsOutOfOrderPolicyAdjust, @@ -286,6 +407,19 @@ func PossibleValuesForInputWatermarkMode() []string { } } +func (s *InputWatermarkMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseInputWatermarkMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseInputWatermarkMode(input string) (*InputWatermarkMode, error) { vals := map[string]InputWatermarkMode{ "none": InputWatermarkModeNone, @@ -314,6 +448,19 @@ func PossibleValuesForJobType() []string { } } +func (s *JobType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseJobType(input string) (*JobType, error) { vals := map[string]JobType{ "cloud": JobTypeCloud, @@ -342,6 +489,19 @@ func PossibleValuesForJsonOutputSerializationFormat() []string { } } +func (s *JsonOutputSerializationFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJsonOutputSerializationFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseJsonOutputSerializationFormat(input string) (*JsonOutputSerializationFormat, error) { vals := map[string]JsonOutputSerializationFormat{ "array": JsonOutputSerializationFormatArray, @@ -370,6 +530,19 @@ func PossibleValuesForOutputErrorPolicy() []string { } } +func (s *OutputErrorPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOutputErrorPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOutputErrorPolicy(input string) (*OutputErrorPolicy, error) { vals := map[string]OutputErrorPolicy{ "drop": OutputErrorPolicyDrop, @@ -400,6 +573,19 @@ func PossibleValuesForOutputStartMode() []string { } } +func (s *OutputStartMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOutputStartMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOutputStartMode(input string) (*OutputStartMode, error) { vals := map[string]OutputStartMode{ "customtime": OutputStartModeCustomTime, @@ -431,6 +617,19 @@ func PossibleValuesForOutputWatermarkMode() []string { } } +func (s *OutputWatermarkMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOutputWatermarkMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOutputWatermarkMode(input string) (*OutputWatermarkMode, error) { vals := map[string]OutputWatermarkMode{ "none": OutputWatermarkModeNone, @@ -462,6 +661,19 @@ func PossibleValuesForRefreshType() []string { } } +func (s *RefreshType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRefreshType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRefreshType(input string) (*RefreshType, error) { vals := map[string]RefreshType{ "refreshperiodicallywithdelta": RefreshTypeRefreshPeriodicallyWithDelta, @@ -489,6 +701,19 @@ func PossibleValuesForResourceType() []string { } } +func (s *ResourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseResourceType(input string) (*ResourceType, error) { vals := map[string]ResourceType{ "microsoft.streamanalytics/streamingjobs": ResourceTypeMicrosoftPointStreamAnalyticsStreamingjobs, @@ -518,6 +743,19 @@ func PossibleValuesForSkuCapacityScaleType() []string { } } +func (s *SkuCapacityScaleType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuCapacityScaleType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSkuCapacityScaleType(input string) (*SkuCapacityScaleType, error) { vals := map[string]SkuCapacityScaleType{ "automatic": SkuCapacityScaleTypeAutomatic, @@ -545,6 +783,19 @@ func PossibleValuesForSkuName() []string { } } +func (s *SkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSkuName(input string) (*SkuName, error) { vals := map[string]SkuName{ "standard": SkuNameStandard, @@ -572,6 +823,19 @@ func PossibleValuesForUpdatableUdfRefreshType() []string { } } +func (s *UpdatableUdfRefreshType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUpdatableUdfRefreshType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseUpdatableUdfRefreshType(input string) (*UpdatableUdfRefreshType, error) { vals := map[string]UpdatableUdfRefreshType{ "blocking": UpdatableUdfRefreshTypeBlocking, @@ -600,6 +864,19 @@ func PossibleValuesForUpdateMode() []string { } } +func (s *UpdateMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUpdateMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseUpdateMode(input string) (*UpdateMode, error) { vals := map[string]UpdateMode{ "refreshable": UpdateModeRefreshable, diff --git a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_createorreplace.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_createorreplace.go new file mode 100644 index 00000000000..95d9cbcf619 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_createorreplace.go @@ -0,0 +1,107 @@ +package streamingjobs + +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 CreateOrReplaceOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *StreamingJob +} + +type CreateOrReplaceOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { + return CreateOrReplaceOperationOptions{} +} + +func (o CreateOrReplaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrReplaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrReplaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrReplace ... +func (c StreamingJobsClient) CreateOrReplace(ctx context.Context, id StreamingJobId, input StreamingJob, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + OptionsObject: options, + } + + 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrReplaceThenPoll performs CreateOrReplace then polls until it's completed +func (c StreamingJobsClient) CreateOrReplaceThenPoll(ctx context.Context, id StreamingJobId, input StreamingJob, options CreateOrReplaceOperationOptions) error { + result, err := c.CreateOrReplace(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing CreateOrReplace: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrReplace: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_createorreplace_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_createorreplace_autorest.go deleted file mode 100644 index 3813ba88427..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_createorreplace_autorest.go +++ /dev/null @@ -1,114 +0,0 @@ -package streamingjobs - -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 CreateOrReplaceOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *StreamingJob -} - -type CreateOrReplaceOperationOptions struct { - IfMatch *string - IfNoneMatch *string -} - -func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { - return CreateOrReplaceOperationOptions{} -} - -func (o CreateOrReplaceOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - if o.IfNoneMatch != nil { - out["If-None-Match"] = *o.IfNoneMatch - } - - return out -} - -func (o CreateOrReplaceOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// CreateOrReplace ... -func (c StreamingJobsClient) CreateOrReplace(ctx context.Context, id StreamingJobId, input StreamingJob, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { - req, err := c.preparerForCreateOrReplace(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "CreateOrReplace", nil, "Failure preparing request") - return - } - - result, err = c.senderForCreateOrReplace(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "CreateOrReplace", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// CreateOrReplaceThenPoll performs CreateOrReplace then polls until it's completed -func (c StreamingJobsClient) CreateOrReplaceThenPoll(ctx context.Context, id StreamingJobId, input StreamingJob, options CreateOrReplaceOperationOptions) error { - result, err := c.CreateOrReplace(ctx, id, input, options) - if err != nil { - return fmt.Errorf("performing CreateOrReplace: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after CreateOrReplace: %+v", err) - } - - return nil -} - -// preparerForCreateOrReplace prepares the CreateOrReplace request. -func (c StreamingJobsClient) preparerForCreateOrReplace(ctx context.Context, id StreamingJobId, input StreamingJob, options CreateOrReplaceOperationOptions) (*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.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForCreateOrReplace sends the CreateOrReplace request. The method will close the -// http.Response Body if it receives an error. -func (c StreamingJobsClient) senderForCreateOrReplace(ctx context.Context, req *http.Request) (future CreateOrReplaceOperationResponse, 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/streamanalytics/2021-10-01-preview/streamingjobs/method_delete.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_delete.go new file mode 100644 index 00000000000..57b2d02ea09 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_delete.go @@ -0,0 +1,71 @@ +package streamingjobs + +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 +} + +// Delete ... +func (c StreamingJobsClient) Delete(ctx context.Context, id StreamingJobId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c StreamingJobsClient) DeleteThenPoll(ctx context.Context, id StreamingJobId) 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/streamanalytics/2021-10-01-preview/streamingjobs/method_delete_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_delete_autorest.go deleted file mode 100644 index d619132add7..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_delete_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package streamingjobs - -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 -} - -// Delete ... -func (c StreamingJobsClient) Delete(ctx context.Context, id StreamingJobId) (result DeleteOperationResponse, err error) { - req, err := c.preparerForDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Delete", nil, "Failure preparing request") - return - } - - result, err = c.senderForDelete(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Delete", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// DeleteThenPoll performs Delete then polls until it's completed -func (c StreamingJobsClient) DeleteThenPoll(ctx context.Context, id StreamingJobId) 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 StreamingJobsClient) preparerForDelete(ctx context.Context, id StreamingJobId) (*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 StreamingJobsClient) 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/streamanalytics/2021-10-01-preview/streamingjobs/method_get.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_get.go new file mode 100644 index 00000000000..3594e9721c5 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_get.go @@ -0,0 +1,80 @@ +package streamingjobs + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StreamingJob +} + +type GetOperationOptions struct { + Expand *string +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// Get ... +func (c StreamingJobsClient) Get(ctx context.Context, id StreamingJobId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: 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/streamanalytics/2021-10-01-preview/streamingjobs/method_get_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_get_autorest.go deleted file mode 100644 index f50e1aaa9e8..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_get_autorest.go +++ /dev/null @@ -1,97 +0,0 @@ -package streamingjobs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *StreamingJob -} - -type GetOperationOptions struct { - Expand *string -} - -func DefaultGetOperationOptions() GetOperationOptions { - return GetOperationOptions{} -} - -func (o GetOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o GetOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Expand != nil { - out["$expand"] = *o.Expand - } - - return out -} - -// Get ... -func (c StreamingJobsClient) Get(ctx context.Context, id StreamingJobId, options GetOperationOptions) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c StreamingJobsClient) preparerForGet(ctx context.Context, id StreamingJobId, options GetOperationOptions) (*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(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 StreamingJobsClient) 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/streamanalytics/2021-10-01-preview/streamingjobs/method_list.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_list.go new file mode 100644 index 00000000000..c2043fdc026 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_list.go @@ -0,0 +1,120 @@ +package streamingjobs + +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 ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StreamingJob +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []StreamingJob +} + +type ListOperationOptions struct { + Expand *string +} + +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.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// List ... +func (c StreamingJobsClient) List(ctx context.Context, id commonids.SubscriptionId, 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.StreamAnalytics/streamingJobs", 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 *[]StreamingJob `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 StreamingJobsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, StreamingJobOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StreamingJobsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate StreamingJobOperationPredicate) (result ListCompleteResult, err error) { + items := make([]StreamingJob, 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/streamanalytics/2021-10-01-preview/streamingjobs/method_list_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_list_autorest.go deleted file mode 100644 index 9c325f2f221..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_list_autorest.go +++ /dev/null @@ -1,216 +0,0 @@ -package streamingjobs - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "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 ListOperationResponse struct { - HttpResponse *http.Response - Model *[]StreamingJob - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) -} - -type ListCompleteResult struct { - Items []StreamingJob -} - -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 { - Expand *string -} - -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.Expand != nil { - out["$expand"] = *o.Expand - } - - return out -} - -// List ... -func (c StreamingJobsClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (resp ListOperationResponse, err error) { - req, err := c.preparerForList(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "List", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "List", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "List", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForList prepares the List request. -func (c StreamingJobsClient) preparerForList(ctx context.Context, id commonids.SubscriptionId, 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.StreamAnalytics/streamingJobs", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListWithNextLink prepares the List request with the given nextLink token. -func (c StreamingJobsClient) 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 StreamingJobsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { - type page struct { - Values []StreamingJob `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, "streamingjobs.StreamingJobsClient", "List", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "List", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "List", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListComplete retrieves all of the results into a single object -func (c StreamingJobsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { - return c.ListCompleteMatchingPredicate(ctx, id, options, StreamingJobOperationPredicate{}) -} - -// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c StreamingJobsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate StreamingJobOperationPredicate) (resp ListCompleteResult, err error) { - items := make([]StreamingJob, 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/streamanalytics/2021-10-01-preview/streamingjobs/method_listbyresourcegroup.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_listbyresourcegroup.go new file mode 100644 index 00000000000..10f76548945 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_listbyresourcegroup.go @@ -0,0 +1,120 @@ +package streamingjobs + +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 ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StreamingJob +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []StreamingJob +} + +type ListByResourceGroupOperationOptions struct { + Expand *string +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + return &out +} + +// ListByResourceGroup ... +func (c StreamingJobsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.StreamAnalytics/streamingJobs", 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 *[]StreamingJob `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c StreamingJobsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, StreamingJobOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StreamingJobsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate StreamingJobOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]StreamingJob, 0) + + resp, err := c.ListByResourceGroup(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 = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_listbyresourcegroup_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_listbyresourcegroup_autorest.go deleted file mode 100644 index 97037ff2975..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_listbyresourcegroup_autorest.go +++ /dev/null @@ -1,216 +0,0 @@ -package streamingjobs - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "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 ListByResourceGroupOperationResponse struct { - HttpResponse *http.Response - Model *[]StreamingJob - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) -} - -type ListByResourceGroupCompleteResult struct { - Items []StreamingJob -} - -func (r ListByResourceGroupOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -type ListByResourceGroupOperationOptions struct { - Expand *string -} - -func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { - return ListByResourceGroupOperationOptions{} -} - -func (o ListByResourceGroupOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -func (o ListByResourceGroupOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - if o.Expand != nil { - out["$expand"] = *o.Expand - } - - return out -} - -// ListByResourceGroup ... -func (c StreamingJobsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (resp ListByResourceGroupOperationResponse, err error) { - req, err := c.preparerForListByResourceGroup(ctx, id, options) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "ListByResourceGroup", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForListByResourceGroup(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForListByResourceGroup prepares the ListByResourceGroup request. -func (c StreamingJobsClient) preparerForListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (*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.StreamAnalytics/streamingJobs", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. -func (c StreamingJobsClient) preparerForListByResourceGroupWithNextLink(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)) -} - -// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always -// closes the http.Response Body. -func (c StreamingJobsClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { - type page struct { - Values []StreamingJob `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 ListByResourceGroupOperationResponse, err error) { - req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "ListByResourceGroup", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListByResourceGroup(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// ListByResourceGroupComplete retrieves all of the results into a single object -func (c StreamingJobsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { - return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, StreamingJobOperationPredicate{}) -} - -// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c StreamingJobsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate StreamingJobOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { - items := make([]StreamingJob, 0) - - page, err := c.ListByResourceGroup(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 := ListByResourceGroupCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_scale.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_scale.go new file mode 100644 index 00000000000..cfc6be30fe9 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_scale.go @@ -0,0 +1,74 @@ +package streamingjobs + +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 ScaleOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Scale ... +func (c StreamingJobsClient) Scale(ctx context.Context, id StreamingJobId, input ScaleStreamingJobParameters) (result ScaleOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/scale", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ScaleThenPoll performs Scale then polls until it's completed +func (c StreamingJobsClient) ScaleThenPoll(ctx context.Context, id StreamingJobId, input ScaleStreamingJobParameters) error { + result, err := c.Scale(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Scale: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Scale: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_scale_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_scale_autorest.go deleted file mode 100644 index 5a54d0da2f4..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_scale_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package streamingjobs - -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 ScaleOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// Scale ... -func (c StreamingJobsClient) Scale(ctx context.Context, id StreamingJobId, input ScaleStreamingJobParameters) (result ScaleOperationResponse, err error) { - req, err := c.preparerForScale(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Scale", nil, "Failure preparing request") - return - } - - result, err = c.senderForScale(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Scale", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// ScaleThenPoll performs Scale then polls until it's completed -func (c StreamingJobsClient) ScaleThenPoll(ctx context.Context, id StreamingJobId, input ScaleStreamingJobParameters) error { - result, err := c.Scale(ctx, id, input) - if err != nil { - return fmt.Errorf("performing Scale: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Scale: %+v", err) - } - - return nil -} - -// preparerForScale prepares the Scale request. -func (c StreamingJobsClient) preparerForScale(ctx context.Context, id StreamingJobId, input ScaleStreamingJobParameters) (*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/scale", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForScale sends the Scale request. The method will close the -// http.Response Body if it receives an error. -func (c StreamingJobsClient) senderForScale(ctx context.Context, req *http.Request) (future ScaleOperationResponse, 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/streamanalytics/2021-10-01-preview/streamingjobs/method_skulist.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_skulist.go new file mode 100644 index 00000000000..8bf54ce538b --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_skulist.go @@ -0,0 +1,91 @@ +package streamingjobs + +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 SkuListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GetStreamingJobSkuResult +} + +type SkuListCompleteResult struct { + LatestHttpResponse *http.Response + Items []GetStreamingJobSkuResult +} + +// SkuList ... +func (c StreamingJobsClient) SkuList(ctx context.Context, id StreamingJobId) (result SkuListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/skus", 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 *[]GetStreamingJobSkuResult `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SkuListComplete retrieves all the results into a single object +func (c StreamingJobsClient) SkuListComplete(ctx context.Context, id StreamingJobId) (SkuListCompleteResult, error) { + return c.SkuListCompleteMatchingPredicate(ctx, id, GetStreamingJobSkuResultOperationPredicate{}) +} + +// SkuListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StreamingJobsClient) SkuListCompleteMatchingPredicate(ctx context.Context, id StreamingJobId, predicate GetStreamingJobSkuResultOperationPredicate) (result SkuListCompleteResult, err error) { + items := make([]GetStreamingJobSkuResult, 0) + + resp, err := c.SkuList(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 = SkuListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_skulist_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_skulist_autorest.go deleted file mode 100644 index 6e734cbe1d9..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_skulist_autorest.go +++ /dev/null @@ -1,186 +0,0 @@ -package streamingjobs - -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 SkuListOperationResponse struct { - HttpResponse *http.Response - Model *[]GetStreamingJobSkuResult - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (SkuListOperationResponse, error) -} - -type SkuListCompleteResult struct { - Items []GetStreamingJobSkuResult -} - -func (r SkuListOperationResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r SkuListOperationResponse) LoadMore(ctx context.Context) (resp SkuListOperationResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// SkuList ... -func (c StreamingJobsClient) SkuList(ctx context.Context, id StreamingJobId) (resp SkuListOperationResponse, err error) { - req, err := c.preparerForSkuList(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "SkuList", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "SkuList", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForSkuList(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "SkuList", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// preparerForSkuList prepares the SkuList request. -func (c StreamingJobsClient) preparerForSkuList(ctx context.Context, id StreamingJobId) (*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/skus", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForSkuListWithNextLink prepares the SkuList request with the given nextLink token. -func (c StreamingJobsClient) preparerForSkuListWithNextLink(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)) -} - -// responderForSkuList handles the response to the SkuList request. The method always -// closes the http.Response Body. -func (c StreamingJobsClient) responderForSkuList(resp *http.Response) (result SkuListOperationResponse, err error) { - type page struct { - Values []GetStreamingJobSkuResult `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 SkuListOperationResponse, err error) { - req, err := c.preparerForSkuListWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "SkuList", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "SkuList", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForSkuList(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "SkuList", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} - -// SkuListComplete retrieves all of the results into a single object -func (c StreamingJobsClient) SkuListComplete(ctx context.Context, id StreamingJobId) (SkuListCompleteResult, error) { - return c.SkuListCompleteMatchingPredicate(ctx, id, GetStreamingJobSkuResultOperationPredicate{}) -} - -// SkuListCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c StreamingJobsClient) SkuListCompleteMatchingPredicate(ctx context.Context, id StreamingJobId, predicate GetStreamingJobSkuResultOperationPredicate) (resp SkuListCompleteResult, err error) { - items := make([]GetStreamingJobSkuResult, 0) - - page, err := c.SkuList(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 := SkuListCompleteResult{ - Items: items, - } - return out, nil -} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_start.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_start.go new file mode 100644 index 00000000000..9ac7656ae02 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_start.go @@ -0,0 +1,74 @@ +package streamingjobs + +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 StartOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Start ... +func (c StreamingJobsClient) Start(ctx context.Context, id StreamingJobId, input StartStreamingJobParameters) (result StartOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/start", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// StartThenPoll performs Start then polls until it's completed +func (c StreamingJobsClient) StartThenPoll(ctx context.Context, id StreamingJobId, input StartStreamingJobParameters) error { + result, err := c.Start(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Start: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Start: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_start_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_start_autorest.go deleted file mode 100644 index eb10a45f098..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_start_autorest.go +++ /dev/null @@ -1,79 +0,0 @@ -package streamingjobs - -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 StartOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// Start ... -func (c StreamingJobsClient) Start(ctx context.Context, id StreamingJobId, input StartStreamingJobParameters) (result StartOperationResponse, err error) { - req, err := c.preparerForStart(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Start", nil, "Failure preparing request") - return - } - - result, err = c.senderForStart(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Start", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// StartThenPoll performs Start then polls until it's completed -func (c StreamingJobsClient) StartThenPoll(ctx context.Context, id StreamingJobId, input StartStreamingJobParameters) error { - result, err := c.Start(ctx, id, input) - if err != nil { - return fmt.Errorf("performing Start: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Start: %+v", err) - } - - return nil -} - -// preparerForStart prepares the Start request. -func (c StreamingJobsClient) preparerForStart(ctx context.Context, id StreamingJobId, input StartStreamingJobParameters) (*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/start", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForStart sends the Start request. The method will close the -// http.Response Body if it receives an error. -func (c StreamingJobsClient) senderForStart(ctx context.Context, req *http.Request) (future StartOperationResponse, 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/streamanalytics/2021-10-01-preview/streamingjobs/method_stop.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_stop.go new file mode 100644 index 00000000000..b4c00370cbe --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_stop.go @@ -0,0 +1,70 @@ +package streamingjobs + +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 StopOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Stop ... +func (c StreamingJobsClient) Stop(ctx context.Context, id StreamingJobId) (result StopOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/stop", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + 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 +} + +// StopThenPoll performs Stop then polls until it's completed +func (c StreamingJobsClient) StopThenPoll(ctx context.Context, id StreamingJobId) error { + result, err := c.Stop(ctx, id) + if err != nil { + return fmt.Errorf("performing Stop: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Stop: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_stop_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_stop_autorest.go deleted file mode 100644 index 1203d28307a..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_stop_autorest.go +++ /dev/null @@ -1,78 +0,0 @@ -package streamingjobs - -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 StopOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// Stop ... -func (c StreamingJobsClient) Stop(ctx context.Context, id StreamingJobId) (result StopOperationResponse, err error) { - req, err := c.preparerForStop(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Stop", nil, "Failure preparing request") - return - } - - result, err = c.senderForStop(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Stop", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// StopThenPoll performs Stop then polls until it's completed -func (c StreamingJobsClient) StopThenPoll(ctx context.Context, id StreamingJobId) error { - result, err := c.Stop(ctx, id) - if err != nil { - return fmt.Errorf("performing Stop: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after Stop: %+v", err) - } - - return nil -} - -// preparerForStop prepares the Stop request. -func (c StreamingJobsClient) preparerForStop(ctx context.Context, id StreamingJobId) (*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/stop", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForStop sends the Stop request. The method will close the -// http.Response Body if it receives an error. -func (c StreamingJobsClient) senderForStop(ctx context.Context, req *http.Request) (future StopOperationResponse, 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/streamanalytics/2021-10-01-preview/streamingjobs/method_update.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_update.go new file mode 100644 index 00000000000..fd85377e1be --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_update.go @@ -0,0 +1,84 @@ +package streamingjobs + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StreamingJob +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c StreamingJobsClient) Update(ctx context.Context, id StreamingJobId, input StreamingJob, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2021-10-01-preview/streamingjobs/method_update_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_update_autorest.go deleted file mode 100644 index 863564082e1..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/streamingjobs/method_update_autorest.go +++ /dev/null @@ -1,98 +0,0 @@ -package streamingjobs - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *StreamingJob -} - -type UpdateOperationOptions struct { - IfMatch *string -} - -func DefaultUpdateOperationOptions() UpdateOperationOptions { - return UpdateOperationOptions{} -} - -func (o UpdateOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - return out -} - -func (o UpdateOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// Update ... -func (c StreamingJobsClient) Update(ctx context.Context, id StreamingJobId, input StreamingJob, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "streamingjobs.StreamingJobsClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c StreamingJobsClient) preparerForUpdate(ctx context.Context, id StreamingJobId, input StreamingJob, options UpdateOperationOptions) (*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.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - 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 StreamingJobsClient) 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/streamanalytics/2021-10-01-preview/subscriptions/client.go b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/client.go index da1257d5d97..09be7cb1cfb 100644 --- a/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/client.go +++ b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/client.go @@ -1,18 +1,26 @@ package subscriptions -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 SubscriptionsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewSubscriptionsClientWithBaseURI(endpoint string) SubscriptionsClient { - return SubscriptionsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewSubscriptionsClientWithBaseURI(sdkApi sdkEnv.Api) (*SubscriptionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "subscriptions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SubscriptionsClient: %+v", err) } + + return &SubscriptionsClient{ + Client: client, + }, nil } diff --git a/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/constants.go b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/constants.go index 263786949f3..f083ce34081 100644 --- a/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/constants.go +++ b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/constants.go @@ -1,6 +1,10 @@ package subscriptions -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 PossibleValuesForAuthenticationMode() []string { } } +func (s *AuthenticationMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAuthenticationMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseAuthenticationMode(input string) (*AuthenticationMode, error) { vals := map[string]AuthenticationMode{ "connectionstring": AuthenticationModeConnectionString, @@ -50,6 +67,19 @@ func PossibleValuesForBlobWriteMode() []string { } } +func (s *BlobWriteMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBlobWriteMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseBlobWriteMode(input string) (*BlobWriteMode, error) { vals := map[string]BlobWriteMode{ "append": BlobWriteModeAppend, @@ -78,6 +108,19 @@ func PossibleValuesForCompatibilityLevel() []string { } } +func (s *CompatibilityLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCompatibilityLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCompatibilityLevel(input string) (*CompatibilityLevel, error) { vals := map[string]CompatibilityLevel{ "1.2": CompatibilityLevelOnePointTwo, @@ -108,6 +151,19 @@ func PossibleValuesForCompressionType() []string { } } +func (s *CompressionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCompressionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseCompressionType(input string) (*CompressionType, error) { vals := map[string]CompressionType{ "deflate": CompressionTypeDeflate, @@ -137,6 +193,19 @@ func PossibleValuesForContentStoragePolicy() []string { } } +func (s *ContentStoragePolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContentStoragePolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseContentStoragePolicy(input string) (*ContentStoragePolicy, error) { vals := map[string]ContentStoragePolicy{ "jobstorageaccount": ContentStoragePolicyJobStorageAccount, @@ -163,6 +232,19 @@ func PossibleValuesForEncoding() []string { } } +func (s *Encoding) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEncoding(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEncoding(input string) (*Encoding, error) { vals := map[string]Encoding{ "utf8": EncodingUTFEight, @@ -190,6 +272,19 @@ func PossibleValuesForEventGridEventSchemaType() []string { } } +func (s *EventGridEventSchemaType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGridEventSchemaType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventGridEventSchemaType(input string) (*EventGridEventSchemaType, error) { vals := map[string]EventGridEventSchemaType{ "cloudeventschema": EventGridEventSchemaTypeCloudEventSchema, @@ -226,6 +321,19 @@ func PossibleValuesForEventSerializationType() []string { } } +func (s *EventSerializationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventSerializationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventSerializationType(input string) (*EventSerializationType, error) { vals := map[string]EventSerializationType{ "avro": EventSerializationTypeAvro, @@ -258,6 +366,19 @@ func PossibleValuesForEventsOutOfOrderPolicy() []string { } } +func (s *EventsOutOfOrderPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventsOutOfOrderPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseEventsOutOfOrderPolicy(input string) (*EventsOutOfOrderPolicy, error) { vals := map[string]EventsOutOfOrderPolicy{ "adjust": EventsOutOfOrderPolicyAdjust, @@ -286,6 +407,19 @@ func PossibleValuesForInputWatermarkMode() []string { } } +func (s *InputWatermarkMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseInputWatermarkMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseInputWatermarkMode(input string) (*InputWatermarkMode, error) { vals := map[string]InputWatermarkMode{ "none": InputWatermarkModeNone, @@ -314,6 +448,19 @@ func PossibleValuesForJobType() []string { } } +func (s *JobType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJobType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseJobType(input string) (*JobType, error) { vals := map[string]JobType{ "cloud": JobTypeCloud, @@ -342,6 +489,19 @@ func PossibleValuesForJsonOutputSerializationFormat() []string { } } +func (s *JsonOutputSerializationFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseJsonOutputSerializationFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseJsonOutputSerializationFormat(input string) (*JsonOutputSerializationFormat, error) { vals := map[string]JsonOutputSerializationFormat{ "array": JsonOutputSerializationFormatArray, @@ -370,6 +530,19 @@ func PossibleValuesForOutputErrorPolicy() []string { } } +func (s *OutputErrorPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOutputErrorPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOutputErrorPolicy(input string) (*OutputErrorPolicy, error) { vals := map[string]OutputErrorPolicy{ "drop": OutputErrorPolicyDrop, @@ -400,6 +573,19 @@ func PossibleValuesForOutputStartMode() []string { } } +func (s *OutputStartMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOutputStartMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOutputStartMode(input string) (*OutputStartMode, error) { vals := map[string]OutputStartMode{ "customtime": OutputStartModeCustomTime, @@ -431,6 +617,19 @@ func PossibleValuesForOutputWatermarkMode() []string { } } +func (s *OutputWatermarkMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOutputWatermarkMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseOutputWatermarkMode(input string) (*OutputWatermarkMode, error) { vals := map[string]OutputWatermarkMode{ "none": OutputWatermarkModeNone, @@ -468,6 +667,19 @@ func PossibleValuesForQueryTestingResultStatus() []string { } } +func (s *QueryTestingResultStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQueryTestingResultStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseQueryTestingResultStatus(input string) (*QueryTestingResultStatus, error) { vals := map[string]QueryTestingResultStatus{ "compilererror": QueryTestingResultStatusCompilerError, @@ -502,6 +714,19 @@ func PossibleValuesForRefreshType() []string { } } +func (s *RefreshType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRefreshType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseRefreshType(input string) (*RefreshType, error) { vals := map[string]RefreshType{ "refreshperiodicallywithdelta": RefreshTypeRefreshPeriodicallyWithDelta, @@ -533,6 +758,19 @@ func PossibleValuesForSampleInputResultStatus() []string { } } +func (s *SampleInputResultStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSampleInputResultStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSampleInputResultStatus(input string) (*SampleInputResultStatus, error) { vals := map[string]SampleInputResultStatus{ "errorconnectingtoinput": SampleInputResultStatusErrorConnectingToInput, @@ -560,6 +798,19 @@ func PossibleValuesForSkuName() []string { } } +func (s *SkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseSkuName(input string) (*SkuName, error) { vals := map[string]SkuName{ "standard": SkuNameStandard, @@ -587,6 +838,19 @@ func PossibleValuesForTestDatasourceResultStatus() []string { } } +func (s *TestDatasourceResultStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTestDatasourceResultStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseTestDatasourceResultStatus(input string) (*TestDatasourceResultStatus, error) { vals := map[string]TestDatasourceResultStatus{ "testfailed": TestDatasourceResultStatusTestFailed, @@ -615,6 +879,19 @@ func PossibleValuesForUpdatableUdfRefreshType() []string { } } +func (s *UpdatableUdfRefreshType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUpdatableUdfRefreshType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseUpdatableUdfRefreshType(input string) (*UpdatableUdfRefreshType, error) { vals := map[string]UpdatableUdfRefreshType{ "blocking": UpdatableUdfRefreshTypeBlocking, @@ -643,6 +920,19 @@ func PossibleValuesForUpdateMode() []string { } } +func (s *UpdateMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUpdateMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + func parseUpdateMode(input string) (*UpdateMode, error) { vals := map[string]UpdateMode{ "refreshable": UpdateModeRefreshable, diff --git a/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_compilequery.go b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_compilequery.go new file mode 100644 index 00000000000..43cc0e5e724 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_compilequery.go @@ -0,0 +1,56 @@ +package subscriptions + +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 CompileQueryOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *QueryCompilationResult +} + +// CompileQuery ... +func (c SubscriptionsClient) CompileQuery(ctx context.Context, id LocationId, input CompileQuery) (result CompileQueryOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/compileQuery", 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/streamanalytics/2021-10-01-preview/subscriptions/method_compilequery_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_compilequery_autorest.go deleted file mode 100644 index ca1f5dafd84..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_compilequery_autorest.go +++ /dev/null @@ -1,70 +0,0 @@ -package subscriptions - -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 CompileQueryOperationResponse struct { - HttpResponse *http.Response - Model *QueryCompilationResult -} - -// CompileQuery ... -func (c SubscriptionsClient) CompileQuery(ctx context.Context, id LocationId, input CompileQuery) (result CompileQueryOperationResponse, err error) { - req, err := c.preparerForCompileQuery(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "CompileQuery", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "CompileQuery", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCompileQuery(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "CompileQuery", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCompileQuery prepares the CompileQuery request. -func (c SubscriptionsClient) preparerForCompileQuery(ctx context.Context, id LocationId, input CompileQuery) (*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/compileQuery", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCompileQuery handles the response to the CompileQuery request. The method always -// closes the http.Response Body. -func (c SubscriptionsClient) responderForCompileQuery(resp *http.Response) (result CompileQueryOperationResponse, 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/streamanalytics/2021-10-01-preview/subscriptions/method_listquotas.go b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_listquotas.go new file mode 100644 index 00000000000..b0ec5d03882 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_listquotas.go @@ -0,0 +1,52 @@ +package subscriptions + +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 ListQuotasOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SubscriptionQuotasListResult +} + +// ListQuotas ... +func (c SubscriptionsClient) ListQuotas(ctx context.Context, id LocationId) (result ListQuotasOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/quotas", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + 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/streamanalytics/2021-10-01-preview/subscriptions/method_listquotas_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_listquotas_autorest.go deleted file mode 100644 index ef8e03ebb23..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_listquotas_autorest.go +++ /dev/null @@ -1,69 +0,0 @@ -package subscriptions - -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 ListQuotasOperationResponse struct { - HttpResponse *http.Response - Model *SubscriptionQuotasListResult -} - -// ListQuotas ... -func (c SubscriptionsClient) ListQuotas(ctx context.Context, id LocationId) (result ListQuotasOperationResponse, err error) { - req, err := c.preparerForListQuotas(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "ListQuotas", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "ListQuotas", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForListQuotas(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "ListQuotas", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForListQuotas prepares the ListQuotas request. -func (c SubscriptionsClient) preparerForListQuotas(ctx context.Context, id LocationId) (*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/quotas", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForListQuotas handles the response to the ListQuotas request. The method always -// closes the http.Response Body. -func (c SubscriptionsClient) responderForListQuotas(resp *http.Response) (result ListQuotasOperationResponse, 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/streamanalytics/2021-10-01-preview/subscriptions/method_sampleinput.go b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_sampleinput.go new file mode 100644 index 00000000000..c29c578f827 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_sampleinput.go @@ -0,0 +1,74 @@ +package subscriptions + +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 SampleInputOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SampleInputResult +} + +// SampleInput ... +func (c SubscriptionsClient) SampleInput(ctx context.Context, id LocationId, input SampleInput) (result SampleInputOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/sampleInput", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// SampleInputThenPoll performs SampleInput then polls until it's completed +func (c SubscriptionsClient) SampleInputThenPoll(ctx context.Context, id LocationId, input SampleInput) error { + result, err := c.SampleInput(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SampleInput: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SampleInput: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_sampleinput_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_sampleinput_autorest.go deleted file mode 100644 index a08b8db1e17..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_sampleinput_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package subscriptions - -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 SampleInputOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *SampleInputResult -} - -// SampleInput ... -func (c SubscriptionsClient) SampleInput(ctx context.Context, id LocationId, input SampleInput) (result SampleInputOperationResponse, err error) { - req, err := c.preparerForSampleInput(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SampleInput", nil, "Failure preparing request") - return - } - - result, err = c.senderForSampleInput(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "SampleInput", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// SampleInputThenPoll performs SampleInput then polls until it's completed -func (c SubscriptionsClient) SampleInputThenPoll(ctx context.Context, id LocationId, input SampleInput) error { - result, err := c.SampleInput(ctx, id, input) - if err != nil { - return fmt.Errorf("performing SampleInput: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after SampleInput: %+v", err) - } - - return nil -} - -// preparerForSampleInput prepares the SampleInput request. -func (c SubscriptionsClient) preparerForSampleInput(ctx context.Context, id LocationId, input SampleInput) (*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/sampleInput", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForSampleInput sends the SampleInput request. The method will close the -// http.Response Body if it receives an error. -func (c SubscriptionsClient) senderForSampleInput(ctx context.Context, req *http.Request) (future SampleInputOperationResponse, 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/streamanalytics/2021-10-01-preview/subscriptions/method_testinput.go b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testinput.go new file mode 100644 index 00000000000..3ca551cd139 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testinput.go @@ -0,0 +1,74 @@ +package subscriptions + +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 TestInputOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *TestDatasourceResult +} + +// TestInput ... +func (c SubscriptionsClient) TestInput(ctx context.Context, id LocationId, input TestInput) (result TestInputOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/testInput", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// TestInputThenPoll performs TestInput then polls until it's completed +func (c SubscriptionsClient) TestInputThenPoll(ctx context.Context, id LocationId, input TestInput) error { + result, err := c.TestInput(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TestInput: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after TestInput: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testinput_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testinput_autorest.go deleted file mode 100644 index 4fe221ef149..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testinput_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package subscriptions - -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 TestInputOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *TestDatasourceResult -} - -// TestInput ... -func (c SubscriptionsClient) TestInput(ctx context.Context, id LocationId, input TestInput) (result TestInputOperationResponse, err error) { - req, err := c.preparerForTestInput(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "TestInput", nil, "Failure preparing request") - return - } - - result, err = c.senderForTestInput(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "TestInput", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// TestInputThenPoll performs TestInput then polls until it's completed -func (c SubscriptionsClient) TestInputThenPoll(ctx context.Context, id LocationId, input TestInput) error { - result, err := c.TestInput(ctx, id, input) - if err != nil { - return fmt.Errorf("performing TestInput: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after TestInput: %+v", err) - } - - return nil -} - -// preparerForTestInput prepares the TestInput request. -func (c SubscriptionsClient) preparerForTestInput(ctx context.Context, id LocationId, input TestInput) (*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/testInput", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForTestInput sends the TestInput request. The method will close the -// http.Response Body if it receives an error. -func (c SubscriptionsClient) senderForTestInput(ctx context.Context, req *http.Request) (future TestInputOperationResponse, 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/streamanalytics/2021-10-01-preview/subscriptions/method_testoutput.go b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testoutput.go new file mode 100644 index 00000000000..9b339cfb661 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testoutput.go @@ -0,0 +1,74 @@ +package subscriptions + +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 TestOutputOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *TestDatasourceResult +} + +// TestOutput ... +func (c SubscriptionsClient) TestOutput(ctx context.Context, id LocationId, input TestOutput) (result TestOutputOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/testOutput", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// TestOutputThenPoll performs TestOutput then polls until it's completed +func (c SubscriptionsClient) TestOutputThenPoll(ctx context.Context, id LocationId, input TestOutput) error { + result, err := c.TestOutput(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TestOutput: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after TestOutput: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testoutput_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testoutput_autorest.go deleted file mode 100644 index 3f7fee89243..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testoutput_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package subscriptions - -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 TestOutputOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *TestDatasourceResult -} - -// TestOutput ... -func (c SubscriptionsClient) TestOutput(ctx context.Context, id LocationId, input TestOutput) (result TestOutputOperationResponse, err error) { - req, err := c.preparerForTestOutput(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "TestOutput", nil, "Failure preparing request") - return - } - - result, err = c.senderForTestOutput(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "TestOutput", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// TestOutputThenPoll performs TestOutput then polls until it's completed -func (c SubscriptionsClient) TestOutputThenPoll(ctx context.Context, id LocationId, input TestOutput) error { - result, err := c.TestOutput(ctx, id, input) - if err != nil { - return fmt.Errorf("performing TestOutput: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after TestOutput: %+v", err) - } - - return nil -} - -// preparerForTestOutput prepares the TestOutput request. -func (c SubscriptionsClient) preparerForTestOutput(ctx context.Context, id LocationId, input TestOutput) (*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/testOutput", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForTestOutput sends the TestOutput request. The method will close the -// http.Response Body if it receives an error. -func (c SubscriptionsClient) senderForTestOutput(ctx context.Context, req *http.Request) (future TestOutputOperationResponse, 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/streamanalytics/2021-10-01-preview/subscriptions/method_testquery.go b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testquery.go new file mode 100644 index 00000000000..02235db56fc --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testquery.go @@ -0,0 +1,75 @@ +package subscriptions + +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 TestQueryOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *QueryTestingResult +} + +// TestQuery ... +func (c SubscriptionsClient) TestQuery(ctx context.Context, id LocationId, input TestQuery) (result TestQueryOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/testQuery", 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// TestQueryThenPoll performs TestQuery then polls until it's completed +func (c SubscriptionsClient) TestQueryThenPoll(ctx context.Context, id LocationId, input TestQuery) error { + result, err := c.TestQuery(ctx, id, input) + if err != nil { + return fmt.Errorf("performing TestQuery: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after TestQuery: %+v", err) + } + + return nil +} diff --git a/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testquery_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testquery_autorest.go deleted file mode 100644 index 329a86f6da9..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/subscriptions/method_testquery_autorest.go +++ /dev/null @@ -1,80 +0,0 @@ -package subscriptions - -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 TestQueryOperationResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response - Model *QueryTestingResult -} - -// TestQuery ... -func (c SubscriptionsClient) TestQuery(ctx context.Context, id LocationId, input TestQuery) (result TestQueryOperationResponse, err error) { - req, err := c.preparerForTestQuery(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "TestQuery", nil, "Failure preparing request") - return - } - - result, err = c.senderForTestQuery(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "subscriptions.SubscriptionsClient", "TestQuery", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// TestQueryThenPoll performs TestQuery then polls until it's completed -func (c SubscriptionsClient) TestQueryThenPoll(ctx context.Context, id LocationId, input TestQuery) error { - result, err := c.TestQuery(ctx, id, input) - if err != nil { - return fmt.Errorf("performing TestQuery: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after TestQuery: %+v", err) - } - - return nil -} - -// preparerForTestQuery prepares the TestQuery request. -func (c SubscriptionsClient) preparerForTestQuery(ctx context.Context, id LocationId, input TestQuery) (*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/testQuery", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForTestQuery sends the TestQuery request. The method will close the -// http.Response Body if it receives an error. -func (c SubscriptionsClient) senderForTestQuery(ctx context.Context, req *http.Request) (future TestQueryOperationResponse, 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/streamanalytics/2021-10-01-preview/transformations/client.go b/resource-manager/streamanalytics/2021-10-01-preview/transformations/client.go index c2c425400f1..6808261e8bd 100644 --- a/resource-manager/streamanalytics/2021-10-01-preview/transformations/client.go +++ b/resource-manager/streamanalytics/2021-10-01-preview/transformations/client.go @@ -1,18 +1,26 @@ package transformations -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 TransformationsClient struct { - Client autorest.Client - baseUri string + Client *resourcemanager.Client } -func NewTransformationsClientWithBaseURI(endpoint string) TransformationsClient { - return TransformationsClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, +func NewTransformationsClientWithBaseURI(sdkApi sdkEnv.Api) (*TransformationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "transformations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TransformationsClient: %+v", err) } + + return &TransformationsClient{ + Client: client, + }, nil } diff --git a/resource-manager/streamanalytics/2021-10-01-preview/transformations/method_createorreplace.go b/resource-manager/streamanalytics/2021-10-01-preview/transformations/method_createorreplace.go new file mode 100644 index 00000000000..1a1320949ef --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/transformations/method_createorreplace.go @@ -0,0 +1,89 @@ +package transformations + +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 CreateOrReplaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Transformation +} + +type CreateOrReplaceOperationOptions struct { + IfMatch *string + IfNoneMatch *string +} + +func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { + return CreateOrReplaceOperationOptions{} +} + +func (o CreateOrReplaceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CreateOrReplaceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrReplaceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrReplace ... +func (c TransformationsClient) CreateOrReplace(ctx context.Context, id TransformationId, input Transformation, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2021-10-01-preview/transformations/method_createorreplace_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/transformations/method_createorreplace_autorest.go deleted file mode 100644 index aec7a546815..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/transformations/method_createorreplace_autorest.go +++ /dev/null @@ -1,103 +0,0 @@ -package transformations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type CreateOrReplaceOperationResponse struct { - HttpResponse *http.Response - Model *Transformation -} - -type CreateOrReplaceOperationOptions struct { - IfMatch *string - IfNoneMatch *string -} - -func DefaultCreateOrReplaceOperationOptions() CreateOrReplaceOperationOptions { - return CreateOrReplaceOperationOptions{} -} - -func (o CreateOrReplaceOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - if o.IfNoneMatch != nil { - out["If-None-Match"] = *o.IfNoneMatch - } - - return out -} - -func (o CreateOrReplaceOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// CreateOrReplace ... -func (c TransformationsClient) CreateOrReplace(ctx context.Context, id TransformationId, input Transformation, options CreateOrReplaceOperationOptions) (result CreateOrReplaceOperationResponse, err error) { - req, err := c.preparerForCreateOrReplace(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "CreateOrReplace", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "CreateOrReplace", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForCreateOrReplace(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "CreateOrReplace", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForCreateOrReplace prepares the CreateOrReplace request. -func (c TransformationsClient) preparerForCreateOrReplace(ctx context.Context, id TransformationId, input Transformation, options CreateOrReplaceOperationOptions) (*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.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForCreateOrReplace handles the response to the CreateOrReplace request. The method always -// closes the http.Response Body. -func (c TransformationsClient) responderForCreateOrReplace(resp *http.Response) (result CreateOrReplaceOperationResponse, 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/streamanalytics/2021-10-01-preview/transformations/method_get.go b/resource-manager/streamanalytics/2021-10-01-preview/transformations/method_get.go new file mode 100644 index 00000000000..339677722dd --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/transformations/method_get.go @@ -0,0 +1,51 @@ +package transformations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Transformation +} + +// Get ... +func (c TransformationsClient) Get(ctx context.Context, id TransformationId) (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/streamanalytics/2021-10-01-preview/transformations/method_get_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/transformations/method_get_autorest.go deleted file mode 100644 index d8ebe853c6a..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/transformations/method_get_autorest.go +++ /dev/null @@ -1,68 +0,0 @@ -package transformations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Transformation -} - -// Get ... -func (c TransformationsClient) Get(ctx context.Context, id TransformationId) (result GetOperationResponse, err error) { - req, err := c.preparerForGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "Get", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "Get", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "Get", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForGet prepares the Get request. -func (c TransformationsClient) preparerForGet(ctx context.Context, id TransformationId) (*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 TransformationsClient) 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/streamanalytics/2021-10-01-preview/transformations/method_update.go b/resource-manager/streamanalytics/2021-10-01-preview/transformations/method_update.go new file mode 100644 index 00000000000..3bf38dabf14 --- /dev/null +++ b/resource-manager/streamanalytics/2021-10-01-preview/transformations/method_update.go @@ -0,0 +1,84 @@ +package transformations + +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 UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Transformation +} + +type UpdateOperationOptions struct { + IfMatch *string +} + +func DefaultUpdateOperationOptions() UpdateOperationOptions { + return UpdateOperationOptions{} +} + +func (o UpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o UpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o UpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Update ... +func (c TransformationsClient) Update(ctx context.Context, id TransformationId, input Transformation, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + OptionsObject: options, + } + + 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/streamanalytics/2021-10-01-preview/transformations/method_update_autorest.go b/resource-manager/streamanalytics/2021-10-01-preview/transformations/method_update_autorest.go deleted file mode 100644 index a5d5ea20798..00000000000 --- a/resource-manager/streamanalytics/2021-10-01-preview/transformations/method_update_autorest.go +++ /dev/null @@ -1,98 +0,0 @@ -package transformations - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/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 *Transformation -} - -type UpdateOperationOptions struct { - IfMatch *string -} - -func DefaultUpdateOperationOptions() UpdateOperationOptions { - return UpdateOperationOptions{} -} - -func (o UpdateOperationOptions) toHeaders() map[string]interface{} { - out := make(map[string]interface{}) - - if o.IfMatch != nil { - out["If-Match"] = *o.IfMatch - } - - return out -} - -func (o UpdateOperationOptions) toQueryString() map[string]interface{} { - out := make(map[string]interface{}) - - return out -} - -// Update ... -func (c TransformationsClient) Update(ctx context.Context, id TransformationId, input Transformation, options UpdateOperationOptions) (result UpdateOperationResponse, err error) { - req, err := c.preparerForUpdate(ctx, id, input, options) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "Update", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "Update", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "transformations.TransformationsClient", "Update", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForUpdate prepares the Update request. -func (c TransformationsClient) preparerForUpdate(ctx context.Context, id TransformationId, input Transformation, options UpdateOperationOptions) (*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.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithHeaders(options.toHeaders()), - 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 TransformationsClient) 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 -}