1package apimanagement 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/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// DeletedServicesClient is the apiManagement Client 19type DeletedServicesClient struct { 20 BaseClient 21} 22 23// NewDeletedServicesClient creates an instance of the DeletedServicesClient client. 24func NewDeletedServicesClient(subscriptionID string) DeletedServicesClient { 25 return NewDeletedServicesClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewDeletedServicesClientWithBaseURI creates an instance of the DeletedServicesClient client using a custom endpoint. 29// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewDeletedServicesClientWithBaseURI(baseURI string, subscriptionID string) DeletedServicesClient { 31 return DeletedServicesClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// GetByName get soft-deleted Api Management Service by name. 35// Parameters: 36// serviceName - the name of the API Management service. 37// location - the location of the deleted API Management service. 38func (client DeletedServicesClient) GetByName(ctx context.Context, serviceName string, location string) (result DeletedServiceContract, err error) { 39 if tracing.IsEnabled() { 40 ctx = tracing.StartSpan(ctx, fqdn+"/DeletedServicesClient.GetByName") 41 defer func() { 42 sc := -1 43 if result.Response.Response != nil { 44 sc = result.Response.Response.StatusCode 45 } 46 tracing.EndSpan(ctx, sc, err) 47 }() 48 } 49 if err := validation.Validate([]validation.Validation{ 50 {TargetValue: serviceName, 51 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 52 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 53 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 54 return result, validation.NewError("apimanagement.DeletedServicesClient", "GetByName", err.Error()) 55 } 56 57 req, err := client.GetByNamePreparer(ctx, serviceName, location) 58 if err != nil { 59 err = autorest.NewErrorWithError(err, "apimanagement.DeletedServicesClient", "GetByName", nil, "Failure preparing request") 60 return 61 } 62 63 resp, err := client.GetByNameSender(req) 64 if err != nil { 65 result.Response = autorest.Response{Response: resp} 66 err = autorest.NewErrorWithError(err, "apimanagement.DeletedServicesClient", "GetByName", resp, "Failure sending request") 67 return 68 } 69 70 result, err = client.GetByNameResponder(resp) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "apimanagement.DeletedServicesClient", "GetByName", resp, "Failure responding to request") 73 return 74 } 75 76 return 77} 78 79// GetByNamePreparer prepares the GetByName request. 80func (client DeletedServicesClient) GetByNamePreparer(ctx context.Context, serviceName string, location string) (*http.Request, error) { 81 pathParameters := map[string]interface{}{ 82 "location": autorest.Encode("path", location), 83 "serviceName": autorest.Encode("path", serviceName), 84 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 85 } 86 87 const APIVersion = "2020-12-01" 88 queryParameters := map[string]interface{}{ 89 "api-version": APIVersion, 90 } 91 92 preparer := autorest.CreatePreparer( 93 autorest.AsGet(), 94 autorest.WithBaseURL(client.BaseURI), 95 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.ApiManagement/locations/{location}/deletedservices/{serviceName}", pathParameters), 96 autorest.WithQueryParameters(queryParameters)) 97 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 98} 99 100// GetByNameSender sends the GetByName request. The method will close the 101// http.Response Body if it receives an error. 102func (client DeletedServicesClient) GetByNameSender(req *http.Request) (*http.Response, error) { 103 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 104} 105 106// GetByNameResponder handles the response to the GetByName request. The method always 107// closes the http.Response Body. 108func (client DeletedServicesClient) GetByNameResponder(resp *http.Response) (result DeletedServiceContract, err error) { 109 err = autorest.Respond( 110 resp, 111 azure.WithErrorUnlessStatusCode(http.StatusOK), 112 autorest.ByUnmarshallingJSON(&result), 113 autorest.ByClosing()) 114 result.Response = autorest.Response{Response: resp} 115 return 116} 117 118// ListBySubscription lists all soft-deleted services available for undelete for the given subscription. 119func (client DeletedServicesClient) ListBySubscription(ctx context.Context) (result DeletedServicesCollectionPage, err error) { 120 if tracing.IsEnabled() { 121 ctx = tracing.StartSpan(ctx, fqdn+"/DeletedServicesClient.ListBySubscription") 122 defer func() { 123 sc := -1 124 if result.dsc.Response.Response != nil { 125 sc = result.dsc.Response.Response.StatusCode 126 } 127 tracing.EndSpan(ctx, sc, err) 128 }() 129 } 130 result.fn = client.listBySubscriptionNextResults 131 req, err := client.ListBySubscriptionPreparer(ctx) 132 if err != nil { 133 err = autorest.NewErrorWithError(err, "apimanagement.DeletedServicesClient", "ListBySubscription", nil, "Failure preparing request") 134 return 135 } 136 137 resp, err := client.ListBySubscriptionSender(req) 138 if err != nil { 139 result.dsc.Response = autorest.Response{Response: resp} 140 err = autorest.NewErrorWithError(err, "apimanagement.DeletedServicesClient", "ListBySubscription", resp, "Failure sending request") 141 return 142 } 143 144 result.dsc, err = client.ListBySubscriptionResponder(resp) 145 if err != nil { 146 err = autorest.NewErrorWithError(err, "apimanagement.DeletedServicesClient", "ListBySubscription", resp, "Failure responding to request") 147 return 148 } 149 if result.dsc.hasNextLink() && result.dsc.IsEmpty() { 150 err = result.NextWithContext(ctx) 151 return 152 } 153 154 return 155} 156 157// ListBySubscriptionPreparer prepares the ListBySubscription request. 158func (client DeletedServicesClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) { 159 pathParameters := map[string]interface{}{ 160 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 161 } 162 163 const APIVersion = "2020-12-01" 164 queryParameters := map[string]interface{}{ 165 "api-version": APIVersion, 166 } 167 168 preparer := autorest.CreatePreparer( 169 autorest.AsGet(), 170 autorest.WithBaseURL(client.BaseURI), 171 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.ApiManagement/deletedservices", pathParameters), 172 autorest.WithQueryParameters(queryParameters)) 173 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 174} 175 176// ListBySubscriptionSender sends the ListBySubscription request. The method will close the 177// http.Response Body if it receives an error. 178func (client DeletedServicesClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) { 179 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 180} 181 182// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always 183// closes the http.Response Body. 184func (client DeletedServicesClient) ListBySubscriptionResponder(resp *http.Response) (result DeletedServicesCollection, err error) { 185 err = autorest.Respond( 186 resp, 187 azure.WithErrorUnlessStatusCode(http.StatusOK), 188 autorest.ByUnmarshallingJSON(&result), 189 autorest.ByClosing()) 190 result.Response = autorest.Response{Response: resp} 191 return 192} 193 194// listBySubscriptionNextResults retrieves the next set of results, if any. 195func (client DeletedServicesClient) listBySubscriptionNextResults(ctx context.Context, lastResults DeletedServicesCollection) (result DeletedServicesCollection, err error) { 196 req, err := lastResults.deletedServicesCollectionPreparer(ctx) 197 if err != nil { 198 return result, autorest.NewErrorWithError(err, "apimanagement.DeletedServicesClient", "listBySubscriptionNextResults", nil, "Failure preparing next results request") 199 } 200 if req == nil { 201 return 202 } 203 resp, err := client.ListBySubscriptionSender(req) 204 if err != nil { 205 result.Response = autorest.Response{Response: resp} 206 return result, autorest.NewErrorWithError(err, "apimanagement.DeletedServicesClient", "listBySubscriptionNextResults", resp, "Failure sending next results request") 207 } 208 result, err = client.ListBySubscriptionResponder(resp) 209 if err != nil { 210 err = autorest.NewErrorWithError(err, "apimanagement.DeletedServicesClient", "listBySubscriptionNextResults", resp, "Failure responding to next results request") 211 } 212 return 213} 214 215// ListBySubscriptionComplete enumerates all values, automatically crossing page boundaries as required. 216func (client DeletedServicesClient) ListBySubscriptionComplete(ctx context.Context) (result DeletedServicesCollectionIterator, err error) { 217 if tracing.IsEnabled() { 218 ctx = tracing.StartSpan(ctx, fqdn+"/DeletedServicesClient.ListBySubscription") 219 defer func() { 220 sc := -1 221 if result.Response().Response.Response != nil { 222 sc = result.page.Response().Response.Response.StatusCode 223 } 224 tracing.EndSpan(ctx, sc, err) 225 }() 226 } 227 result.page, err = client.ListBySubscription(ctx) 228 return 229} 230 231// Purge purges Api Management Service (deletes it with no option to undelete). 232// Parameters: 233// serviceName - the name of the API Management service. 234// location - the location of the deleted API Management service. 235func (client DeletedServicesClient) Purge(ctx context.Context, serviceName string, location string) (result DeletedServicesPurgeFuture, err error) { 236 if tracing.IsEnabled() { 237 ctx = tracing.StartSpan(ctx, fqdn+"/DeletedServicesClient.Purge") 238 defer func() { 239 sc := -1 240 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 241 sc = result.FutureAPI.Response().StatusCode 242 } 243 tracing.EndSpan(ctx, sc, err) 244 }() 245 } 246 if err := validation.Validate([]validation.Validation{ 247 {TargetValue: serviceName, 248 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 249 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 250 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 251 return result, validation.NewError("apimanagement.DeletedServicesClient", "Purge", err.Error()) 252 } 253 254 req, err := client.PurgePreparer(ctx, serviceName, location) 255 if err != nil { 256 err = autorest.NewErrorWithError(err, "apimanagement.DeletedServicesClient", "Purge", nil, "Failure preparing request") 257 return 258 } 259 260 result, err = client.PurgeSender(req) 261 if err != nil { 262 err = autorest.NewErrorWithError(err, "apimanagement.DeletedServicesClient", "Purge", nil, "Failure sending request") 263 return 264 } 265 266 return 267} 268 269// PurgePreparer prepares the Purge request. 270func (client DeletedServicesClient) PurgePreparer(ctx context.Context, serviceName string, location string) (*http.Request, error) { 271 pathParameters := map[string]interface{}{ 272 "location": autorest.Encode("path", location), 273 "serviceName": autorest.Encode("path", serviceName), 274 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 275 } 276 277 const APIVersion = "2020-12-01" 278 queryParameters := map[string]interface{}{ 279 "api-version": APIVersion, 280 } 281 282 preparer := autorest.CreatePreparer( 283 autorest.AsDelete(), 284 autorest.WithBaseURL(client.BaseURI), 285 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.ApiManagement/locations/{location}/deletedservices/{serviceName}", pathParameters), 286 autorest.WithQueryParameters(queryParameters)) 287 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 288} 289 290// PurgeSender sends the Purge request. The method will close the 291// http.Response Body if it receives an error. 292func (client DeletedServicesClient) PurgeSender(req *http.Request) (future DeletedServicesPurgeFuture, err error) { 293 var resp *http.Response 294 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 295 if err != nil { 296 return 297 } 298 var azf azure.Future 299 azf, err = azure.NewFutureFromResponse(resp) 300 future.FutureAPI = &azf 301 future.Result = future.result 302 return 303} 304 305// PurgeResponder handles the response to the Purge request. The method always 306// closes the http.Response Body. 307func (client DeletedServicesClient) PurgeResponder(resp *http.Response) (result DeletedServiceContract, err error) { 308 err = autorest.Respond( 309 resp, 310 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 311 autorest.ByUnmarshallingJSON(&result), 312 autorest.ByClosing()) 313 result.Response = autorest.Response{Response: resp} 314 return 315} 316