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) 18 19// SharedGalleryImageVersionsClient contains the methods for the SharedGalleryImageVersions group. 20// Don't use this type directly, use NewSharedGalleryImageVersionsClient() instead. 21type SharedGalleryImageVersionsClient struct { 22 con *armcore.Connection 23 subscriptionID string 24} 25 26// NewSharedGalleryImageVersionsClient creates a new instance of SharedGalleryImageVersionsClient with the specified values. 27func NewSharedGalleryImageVersionsClient(con *armcore.Connection, subscriptionID string) *SharedGalleryImageVersionsClient { 28 return &SharedGalleryImageVersionsClient{con: con, subscriptionID: subscriptionID} 29} 30 31// Get - Get a shared gallery image version by subscription id or tenant id. 32func (client *SharedGalleryImageVersionsClient) Get(ctx context.Context, location string, galleryUniqueName string, galleryImageName string, galleryImageVersionName string, options *SharedGalleryImageVersionsGetOptions) (SharedGalleryImageVersionResponse, error) { 33 req, err := client.getCreateRequest(ctx, location, galleryUniqueName, galleryImageName, galleryImageVersionName, options) 34 if err != nil { 35 return SharedGalleryImageVersionResponse{}, err 36 } 37 resp, err := client.con.Pipeline().Do(req) 38 if err != nil { 39 return SharedGalleryImageVersionResponse{}, err 40 } 41 if !resp.HasStatusCode(http.StatusOK) { 42 return SharedGalleryImageVersionResponse{}, client.getHandleError(resp) 43 } 44 return client.getHandleResponse(resp) 45} 46 47// getCreateRequest creates the Get request. 48func (client *SharedGalleryImageVersionsClient) getCreateRequest(ctx context.Context, location string, galleryUniqueName string, galleryImageName string, galleryImageVersionName string, options *SharedGalleryImageVersionsGetOptions) (*azcore.Request, error) { 49 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/sharedGalleries/{galleryUniqueName}/images/{galleryImageName}/versions/{galleryImageVersionName}" 50 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 51 urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location)) 52 urlPath = strings.ReplaceAll(urlPath, "{galleryUniqueName}", url.PathEscape(galleryUniqueName)) 53 urlPath = strings.ReplaceAll(urlPath, "{galleryImageName}", url.PathEscape(galleryImageName)) 54 urlPath = strings.ReplaceAll(urlPath, "{galleryImageVersionName}", url.PathEscape(galleryImageVersionName)) 55 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 56 if err != nil { 57 return nil, err 58 } 59 req.Telemetry(telemetryInfo) 60 query := req.URL.Query() 61 query.Set("api-version", "2020-09-30") 62 req.URL.RawQuery = query.Encode() 63 req.Header.Set("Accept", "application/json") 64 return req, nil 65} 66 67// getHandleResponse handles the Get response. 68func (client *SharedGalleryImageVersionsClient) getHandleResponse(resp *azcore.Response) (SharedGalleryImageVersionResponse, error) { 69 var val *SharedGalleryImageVersion 70 if err := resp.UnmarshalAsJSON(&val); err != nil { 71 return SharedGalleryImageVersionResponse{}, err 72 } 73 return SharedGalleryImageVersionResponse{RawResponse: resp.Response, SharedGalleryImageVersion: val}, nil 74} 75 76// getHandleError handles the Get error response. 77func (client *SharedGalleryImageVersionsClient) getHandleError(resp *azcore.Response) error { 78 var err CloudError 79 if err := resp.UnmarshalAsJSON(&err); err != nil { 80 return err 81 } 82 return azcore.NewResponseError(&err, resp.Response) 83} 84 85// List - List shared gallery image versions by subscription id or tenant id. 86func (client *SharedGalleryImageVersionsClient) List(location string, galleryUniqueName string, galleryImageName string, options *SharedGalleryImageVersionsListOptions) SharedGalleryImageVersionListPager { 87 return &sharedGalleryImageVersionListPager{ 88 pipeline: client.con.Pipeline(), 89 requester: func(ctx context.Context) (*azcore.Request, error) { 90 return client.listCreateRequest(ctx, location, galleryUniqueName, galleryImageName, options) 91 }, 92 responder: client.listHandleResponse, 93 errorer: client.listHandleError, 94 advancer: func(ctx context.Context, resp SharedGalleryImageVersionListResponse) (*azcore.Request, error) { 95 return azcore.NewRequest(ctx, http.MethodGet, *resp.SharedGalleryImageVersionList.NextLink) 96 }, 97 statusCodes: []int{http.StatusOK}, 98 } 99} 100 101// listCreateRequest creates the List request. 102func (client *SharedGalleryImageVersionsClient) listCreateRequest(ctx context.Context, location string, galleryUniqueName string, galleryImageName string, options *SharedGalleryImageVersionsListOptions) (*azcore.Request, error) { 103 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/sharedGalleries/{galleryUniqueName}/images/{galleryImageName}/versions" 104 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 105 urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location)) 106 urlPath = strings.ReplaceAll(urlPath, "{galleryUniqueName}", url.PathEscape(galleryUniqueName)) 107 urlPath = strings.ReplaceAll(urlPath, "{galleryImageName}", url.PathEscape(galleryImageName)) 108 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 109 if err != nil { 110 return nil, err 111 } 112 req.Telemetry(telemetryInfo) 113 query := req.URL.Query() 114 query.Set("api-version", "2020-09-30") 115 if options != nil && options.SharedTo != nil { 116 query.Set("sharedTo", string(*options.SharedTo)) 117 } 118 req.URL.RawQuery = query.Encode() 119 req.Header.Set("Accept", "application/json") 120 return req, nil 121} 122 123// listHandleResponse handles the List response. 124func (client *SharedGalleryImageVersionsClient) listHandleResponse(resp *azcore.Response) (SharedGalleryImageVersionListResponse, error) { 125 var val *SharedGalleryImageVersionList 126 if err := resp.UnmarshalAsJSON(&val); err != nil { 127 return SharedGalleryImageVersionListResponse{}, err 128 } 129 return SharedGalleryImageVersionListResponse{RawResponse: resp.Response, SharedGalleryImageVersionList: val}, nil 130} 131 132// listHandleError handles the List error response. 133func (client *SharedGalleryImageVersionsClient) listHandleError(resp *azcore.Response) error { 134 var err CloudError 135 if err := resp.UnmarshalAsJSON(&err); err != nil { 136 return err 137 } 138 return azcore.NewResponseError(&err, resp.Response) 139} 140