1// +build go1.13 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// Code generated by Microsoft (R) AutoRest Code Generator. 6// Changes may cause incorrect behavior and will be lost if the code is regenerated. 7 8package armcompute 9 10import ( 11 "context" 12 "github.com/Azure/azure-sdk-for-go/sdk/armcore" 13 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 14 "net/http" 15 "net/url" 16 "strings" 17 "time" 18) 19 20// GallerySharingProfileClient contains the methods for the GallerySharingProfile group. 21// Don't use this type directly, use NewGallerySharingProfileClient() instead. 22type GallerySharingProfileClient struct { 23 con *armcore.Connection 24 subscriptionID string 25} 26 27// NewGallerySharingProfileClient creates a new instance of GallerySharingProfileClient with the specified values. 28func NewGallerySharingProfileClient(con *armcore.Connection, subscriptionID string) *GallerySharingProfileClient { 29 return &GallerySharingProfileClient{con: con, subscriptionID: subscriptionID} 30} 31 32// BeginUpdate - Update sharing profile of a gallery. 33func (client *GallerySharingProfileClient) BeginUpdate(ctx context.Context, resourceGroupName string, galleryName string, sharingUpdate SharingUpdate, options *GallerySharingProfileBeginUpdateOptions) (SharingUpdatePollerResponse, error) { 34 resp, err := client.update(ctx, resourceGroupName, galleryName, sharingUpdate, options) 35 if err != nil { 36 return SharingUpdatePollerResponse{}, err 37 } 38 result := SharingUpdatePollerResponse{ 39 RawResponse: resp.Response, 40 } 41 pt, err := armcore.NewPoller("GallerySharingProfileClient.Update", "", resp, client.updateHandleError) 42 if err != nil { 43 return SharingUpdatePollerResponse{}, err 44 } 45 poller := &sharingUpdatePoller{ 46 pt: pt, 47 pipeline: client.con.Pipeline(), 48 } 49 result.Poller = poller 50 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (SharingUpdateResponse, error) { 51 return poller.pollUntilDone(ctx, frequency) 52 } 53 return result, nil 54} 55 56// ResumeUpdate creates a new SharingUpdatePoller from the specified resume token. 57// token - The value must come from a previous call to SharingUpdatePoller.ResumeToken(). 58func (client *GallerySharingProfileClient) ResumeUpdate(token string) (SharingUpdatePoller, error) { 59 pt, err := armcore.NewPollerFromResumeToken("GallerySharingProfileClient.Update", token, client.updateHandleError) 60 if err != nil { 61 return nil, err 62 } 63 return &sharingUpdatePoller{ 64 pipeline: client.con.Pipeline(), 65 pt: pt, 66 }, nil 67} 68 69// Update - Update sharing profile of a gallery. 70func (client *GallerySharingProfileClient) update(ctx context.Context, resourceGroupName string, galleryName string, sharingUpdate SharingUpdate, options *GallerySharingProfileBeginUpdateOptions) (*azcore.Response, error) { 71 req, err := client.updateCreateRequest(ctx, resourceGroupName, galleryName, sharingUpdate, options) 72 if err != nil { 73 return nil, err 74 } 75 resp, err := client.con.Pipeline().Do(req) 76 if err != nil { 77 return nil, err 78 } 79 if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted) { 80 return nil, client.updateHandleError(resp) 81 } 82 return resp, nil 83} 84 85// updateCreateRequest creates the Update request. 86func (client *GallerySharingProfileClient) updateCreateRequest(ctx context.Context, resourceGroupName string, galleryName string, sharingUpdate SharingUpdate, options *GallerySharingProfileBeginUpdateOptions) (*azcore.Request, error) { 87 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/share" 88 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 89 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 90 urlPath = strings.ReplaceAll(urlPath, "{galleryName}", url.PathEscape(galleryName)) 91 req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 92 if err != nil { 93 return nil, err 94 } 95 req.Telemetry(telemetryInfo) 96 query := req.URL.Query() 97 query.Set("api-version", "2020-09-30") 98 req.URL.RawQuery = query.Encode() 99 req.Header.Set("Accept", "application/json") 100 return req, req.MarshalAsJSON(sharingUpdate) 101} 102 103// updateHandleResponse handles the Update response. 104func (client *GallerySharingProfileClient) updateHandleResponse(resp *azcore.Response) (SharingUpdateResponse, error) { 105 var val *SharingUpdate 106 if err := resp.UnmarshalAsJSON(&val); err != nil { 107 return SharingUpdateResponse{}, err 108 } 109 return SharingUpdateResponse{RawResponse: resp.Response, SharingUpdate: val}, nil 110} 111 112// updateHandleError handles the Update error response. 113func (client *GallerySharingProfileClient) updateHandleError(resp *azcore.Response) error { 114 var err CloudError 115 if err := resp.UnmarshalAsJSON(&err); err != nil { 116 return err 117 } 118 return azcore.NewResponseError(&err, resp.Response) 119} 120