1package compute 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// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/tracing" 14 "net/http" 15) 16 17// SharedGalleryImageVersionsClient is the compute Client 18type SharedGalleryImageVersionsClient struct { 19 BaseClient 20} 21 22// NewSharedGalleryImageVersionsClient creates an instance of the SharedGalleryImageVersionsClient client. 23func NewSharedGalleryImageVersionsClient(subscriptionID string) SharedGalleryImageVersionsClient { 24 return NewSharedGalleryImageVersionsClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewSharedGalleryImageVersionsClientWithBaseURI creates an instance of the SharedGalleryImageVersionsClient client 28// using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 29// clouds, Azure stack). 30func NewSharedGalleryImageVersionsClientWithBaseURI(baseURI string, subscriptionID string) SharedGalleryImageVersionsClient { 31 return SharedGalleryImageVersionsClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// Get get a shared gallery image version by subscription id or tenant id. 35// Parameters: 36// location - resource location. 37// galleryUniqueName - the unique name of the Shared Gallery. 38// galleryImageName - the name of the Shared Gallery Image Definition from which the Image Versions are to be 39// listed. 40// galleryImageVersionName - the name of the gallery image version to be created. Needs to follow semantic 41// version name pattern: The allowed characters are digit and period. Digits must be within the range of a 42// 32-bit integer. Format: <MajorVersion>.<MinorVersion>.<Patch> 43func (client SharedGalleryImageVersionsClient) Get(ctx context.Context, location string, galleryUniqueName string, galleryImageName string, galleryImageVersionName string) (result SharedGalleryImageVersion, err error) { 44 if tracing.IsEnabled() { 45 ctx = tracing.StartSpan(ctx, fqdn+"/SharedGalleryImageVersionsClient.Get") 46 defer func() { 47 sc := -1 48 if result.Response.Response != nil { 49 sc = result.Response.Response.StatusCode 50 } 51 tracing.EndSpan(ctx, sc, err) 52 }() 53 } 54 req, err := client.GetPreparer(ctx, location, galleryUniqueName, galleryImageName, galleryImageVersionName) 55 if err != nil { 56 err = autorest.NewErrorWithError(err, "compute.SharedGalleryImageVersionsClient", "Get", nil, "Failure preparing request") 57 return 58 } 59 60 resp, err := client.GetSender(req) 61 if err != nil { 62 result.Response = autorest.Response{Response: resp} 63 err = autorest.NewErrorWithError(err, "compute.SharedGalleryImageVersionsClient", "Get", resp, "Failure sending request") 64 return 65 } 66 67 result, err = client.GetResponder(resp) 68 if err != nil { 69 err = autorest.NewErrorWithError(err, "compute.SharedGalleryImageVersionsClient", "Get", resp, "Failure responding to request") 70 return 71 } 72 73 return 74} 75 76// GetPreparer prepares the Get request. 77func (client SharedGalleryImageVersionsClient) GetPreparer(ctx context.Context, location string, galleryUniqueName string, galleryImageName string, galleryImageVersionName string) (*http.Request, error) { 78 pathParameters := map[string]interface{}{ 79 "galleryImageName": autorest.Encode("path", galleryImageName), 80 "galleryImageVersionName": autorest.Encode("path", galleryImageVersionName), 81 "galleryUniqueName": autorest.Encode("path", galleryUniqueName), 82 "location": autorest.Encode("path", location), 83 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 84 } 85 86 const APIVersion = "2020-09-30" 87 queryParameters := map[string]interface{}{ 88 "api-version": APIVersion, 89 } 90 91 preparer := autorest.CreatePreparer( 92 autorest.AsGet(), 93 autorest.WithBaseURL(client.BaseURI), 94 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/sharedGalleries/{galleryUniqueName}/images/{galleryImageName}/versions/{galleryImageVersionName}", pathParameters), 95 autorest.WithQueryParameters(queryParameters)) 96 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 97} 98 99// GetSender sends the Get request. The method will close the 100// http.Response Body if it receives an error. 101func (client SharedGalleryImageVersionsClient) GetSender(req *http.Request) (*http.Response, error) { 102 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 103} 104 105// GetResponder handles the response to the Get request. The method always 106// closes the http.Response Body. 107func (client SharedGalleryImageVersionsClient) GetResponder(resp *http.Response) (result SharedGalleryImageVersion, err error) { 108 err = autorest.Respond( 109 resp, 110 azure.WithErrorUnlessStatusCode(http.StatusOK), 111 autorest.ByUnmarshallingJSON(&result), 112 autorest.ByClosing()) 113 result.Response = autorest.Response{Response: resp} 114 return 115} 116 117// List list shared gallery image versions by subscription id or tenant id. 118// Parameters: 119// location - resource location. 120// galleryUniqueName - the unique name of the Shared Gallery. 121// galleryImageName - the name of the Shared Gallery Image Definition from which the Image Versions are to be 122// listed. 123// sharedTo - the query parameter to decide what shared galleries to fetch when doing listing operations. 124func (client SharedGalleryImageVersionsClient) List(ctx context.Context, location string, galleryUniqueName string, galleryImageName string, sharedTo SharedToValues) (result SharedGalleryImageVersionListPage, err error) { 125 if tracing.IsEnabled() { 126 ctx = tracing.StartSpan(ctx, fqdn+"/SharedGalleryImageVersionsClient.List") 127 defer func() { 128 sc := -1 129 if result.sgivl.Response.Response != nil { 130 sc = result.sgivl.Response.Response.StatusCode 131 } 132 tracing.EndSpan(ctx, sc, err) 133 }() 134 } 135 result.fn = client.listNextResults 136 req, err := client.ListPreparer(ctx, location, galleryUniqueName, galleryImageName, sharedTo) 137 if err != nil { 138 err = autorest.NewErrorWithError(err, "compute.SharedGalleryImageVersionsClient", "List", nil, "Failure preparing request") 139 return 140 } 141 142 resp, err := client.ListSender(req) 143 if err != nil { 144 result.sgivl.Response = autorest.Response{Response: resp} 145 err = autorest.NewErrorWithError(err, "compute.SharedGalleryImageVersionsClient", "List", resp, "Failure sending request") 146 return 147 } 148 149 result.sgivl, err = client.ListResponder(resp) 150 if err != nil { 151 err = autorest.NewErrorWithError(err, "compute.SharedGalleryImageVersionsClient", "List", resp, "Failure responding to request") 152 return 153 } 154 if result.sgivl.hasNextLink() && result.sgivl.IsEmpty() { 155 err = result.NextWithContext(ctx) 156 return 157 } 158 159 return 160} 161 162// ListPreparer prepares the List request. 163func (client SharedGalleryImageVersionsClient) ListPreparer(ctx context.Context, location string, galleryUniqueName string, galleryImageName string, sharedTo SharedToValues) (*http.Request, error) { 164 pathParameters := map[string]interface{}{ 165 "galleryImageName": autorest.Encode("path", galleryImageName), 166 "galleryUniqueName": autorest.Encode("path", galleryUniqueName), 167 "location": autorest.Encode("path", location), 168 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 169 } 170 171 const APIVersion = "2020-09-30" 172 queryParameters := map[string]interface{}{ 173 "api-version": APIVersion, 174 } 175 if len(string(sharedTo)) > 0 { 176 queryParameters["sharedTo"] = autorest.Encode("query", sharedTo) 177 } 178 179 preparer := autorest.CreatePreparer( 180 autorest.AsGet(), 181 autorest.WithBaseURL(client.BaseURI), 182 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/sharedGalleries/{galleryUniqueName}/images/{galleryImageName}/versions", pathParameters), 183 autorest.WithQueryParameters(queryParameters)) 184 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 185} 186 187// ListSender sends the List request. The method will close the 188// http.Response Body if it receives an error. 189func (client SharedGalleryImageVersionsClient) ListSender(req *http.Request) (*http.Response, error) { 190 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 191} 192 193// ListResponder handles the response to the List request. The method always 194// closes the http.Response Body. 195func (client SharedGalleryImageVersionsClient) ListResponder(resp *http.Response) (result SharedGalleryImageVersionList, err error) { 196 err = autorest.Respond( 197 resp, 198 azure.WithErrorUnlessStatusCode(http.StatusOK), 199 autorest.ByUnmarshallingJSON(&result), 200 autorest.ByClosing()) 201 result.Response = autorest.Response{Response: resp} 202 return 203} 204 205// listNextResults retrieves the next set of results, if any. 206func (client SharedGalleryImageVersionsClient) listNextResults(ctx context.Context, lastResults SharedGalleryImageVersionList) (result SharedGalleryImageVersionList, err error) { 207 req, err := lastResults.sharedGalleryImageVersionListPreparer(ctx) 208 if err != nil { 209 return result, autorest.NewErrorWithError(err, "compute.SharedGalleryImageVersionsClient", "listNextResults", nil, "Failure preparing next results request") 210 } 211 if req == nil { 212 return 213 } 214 resp, err := client.ListSender(req) 215 if err != nil { 216 result.Response = autorest.Response{Response: resp} 217 return result, autorest.NewErrorWithError(err, "compute.SharedGalleryImageVersionsClient", "listNextResults", resp, "Failure sending next results request") 218 } 219 result, err = client.ListResponder(resp) 220 if err != nil { 221 err = autorest.NewErrorWithError(err, "compute.SharedGalleryImageVersionsClient", "listNextResults", resp, "Failure responding to next results request") 222 } 223 return 224} 225 226// ListComplete enumerates all values, automatically crossing page boundaries as required. 227func (client SharedGalleryImageVersionsClient) ListComplete(ctx context.Context, location string, galleryUniqueName string, galleryImageName string, sharedTo SharedToValues) (result SharedGalleryImageVersionListIterator, err error) { 228 if tracing.IsEnabled() { 229 ctx = tracing.StartSpan(ctx, fqdn+"/SharedGalleryImageVersionsClient.List") 230 defer func() { 231 sc := -1 232 if result.Response().Response.Response != nil { 233 sc = result.page.Response().Response.Response.StatusCode 234 } 235 tracing.EndSpan(ctx, sc, err) 236 }() 237 } 238 result.page, err = client.List(ctx, location, galleryUniqueName, galleryImageName, sharedTo) 239 return 240} 241