Skip to content

Commit

Permalink
Merge pull request #937 from hashicorp/auto-pr/ba838fff
Browse files Browse the repository at this point in the history
Auto PR: Regenerating the Go SDK (122d2ef)
  • Loading branch information
tombuildsstuff authored Mar 21, 2024
2 parents 6d8a6dd + 122d2ef commit 444ad7c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ payload := clusters.ClusterPatch{
}


read, err := client.Update(ctx, id, payload)
if err != nil {
if err := client.UpdateThenPoll(ctx, id, payload); err != nil {
// handle the error
}
if model := read.Model; model != nil {
// do something with the model/response object
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ 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
Expand All @@ -22,6 +26,7 @@ func (c ClustersClient) Update(ctx context.Context, id ClusterId, input ClusterP
opts := client.RequestOptions{
ContentType: "application/json; charset=utf-8",
ExpectedStatusCodes: []int{
http.StatusAccepted,
http.StatusOK,
},
HttpMethod: http.MethodPatch,
Expand All @@ -47,12 +52,24 @@ func (c ClustersClient) Update(ctx context.Context, id ClusterId, input ClusterP
return
}

var model Cluster
result.Model = &model

if err = resp.Unmarshal(result.Model); err != nil {
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 ClusterPatch) error {
result, err := c.Update(ctx, id, input)
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
}

0 comments on commit 444ad7c

Please sign in to comment.