...

Source file src/github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2021-06-01/cdn/endpoints.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2021-06-01/cdn

     1  package cdn
     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  
     9  import (
    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  // EndpointsClient is the cdn Management Client
    19  type EndpointsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewEndpointsClient creates an instance of the EndpointsClient client.
    24  func NewEndpointsClient(subscriptionID string) EndpointsClient {
    25  	return NewEndpointsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewEndpointsClientWithBaseURI creates an instance of the EndpointsClient client using a custom endpoint.  Use this
    29  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewEndpointsClientWithBaseURI(baseURI string, subscriptionID string) EndpointsClient {
    31  	return EndpointsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // Create creates a new CDN endpoint with the specified endpoint name under the specified subscription, resource group
    35  // and profile.
    36  // Parameters:
    37  // resourceGroupName - name of the Resource group within the Azure subscription.
    38  // profileName - name of the CDN profile which is unique within the resource group.
    39  // endpointName - name of the endpoint under the profile which is unique globally.
    40  // endpoint - endpoint properties
    41  func (client EndpointsClient) Create(ctx context.Context, resourceGroupName string, profileName string, endpointName string, endpoint Endpoint) (result EndpointsCreateFuture, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.Create")
    44  		defer func() {
    45  			sc := -1
    46  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    47  				sc = result.FutureAPI.Response().StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	if err := validation.Validate([]validation.Validation{
    53  		{TargetValue: resourceGroupName,
    54  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    55  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
    56  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
    57  		{TargetValue: endpoint,
    58  			Constraints: []validation.Constraint{{Target: "endpoint.EndpointProperties", Name: validation.Null, Rule: false,
    59  				Chain: []validation.Constraint{{Target: "endpoint.EndpointProperties.Origins", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
    60  		return result, validation.NewError("cdn.EndpointsClient", "Create", err.Error())
    61  	}
    62  
    63  	req, err := client.CreatePreparer(ctx, resourceGroupName, profileName, endpointName, endpoint)
    64  	if err != nil {
    65  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Create", nil, "Failure preparing request")
    66  		return
    67  	}
    68  
    69  	result, err = client.CreateSender(req)
    70  	if err != nil {
    71  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Create", result.Response(), "Failure sending request")
    72  		return
    73  	}
    74  
    75  	return
    76  }
    77  
    78  // CreatePreparer prepares the Create request.
    79  func (client EndpointsClient) CreatePreparer(ctx context.Context, resourceGroupName string, profileName string, endpointName string, endpoint Endpoint) (*http.Request, error) {
    80  	pathParameters := map[string]interface{}{
    81  		"endpointName":      autorest.Encode("path", endpointName),
    82  		"profileName":       autorest.Encode("path", profileName),
    83  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    84  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    85  	}
    86  
    87  	const APIVersion = "2021-06-01"
    88  	queryParameters := map[string]interface{}{
    89  		"api-version": APIVersion,
    90  	}
    91  
    92  	preparer := autorest.CreatePreparer(
    93  		autorest.AsContentType("application/json; charset=utf-8"),
    94  		autorest.AsPut(),
    95  		autorest.WithBaseURL(client.BaseURI),
    96  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}", pathParameters),
    97  		autorest.WithJSON(endpoint),
    98  		autorest.WithQueryParameters(queryParameters))
    99  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   100  }
   101  
   102  // CreateSender sends the Create request. The method will close the
   103  // http.Response Body if it receives an error.
   104  func (client EndpointsClient) CreateSender(req *http.Request) (future EndpointsCreateFuture, err error) {
   105  	var resp *http.Response
   106  	future.FutureAPI = &azure.Future{}
   107  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   108  	if err != nil {
   109  		return
   110  	}
   111  	var azf azure.Future
   112  	azf, err = azure.NewFutureFromResponse(resp)
   113  	future.FutureAPI = &azf
   114  	future.Result = future.result
   115  	return
   116  }
   117  
   118  // CreateResponder handles the response to the Create request. The method always
   119  // closes the http.Response Body.
   120  func (client EndpointsClient) CreateResponder(resp *http.Response) (result Endpoint, err error) {
   121  	err = autorest.Respond(
   122  		resp,
   123  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
   124  		autorest.ByUnmarshallingJSON(&result),
   125  		autorest.ByClosing())
   126  	result.Response = autorest.Response{Response: resp}
   127  	return
   128  }
   129  
   130  // Delete deletes an existing CDN endpoint with the specified endpoint name under the specified subscription, resource
   131  // group and profile.
   132  // Parameters:
   133  // resourceGroupName - name of the Resource group within the Azure subscription.
   134  // profileName - name of the CDN profile which is unique within the resource group.
   135  // endpointName - name of the endpoint under the profile which is unique globally.
   136  func (client EndpointsClient) Delete(ctx context.Context, resourceGroupName string, profileName string, endpointName string) (result EndpointsDeleteFuture, err error) {
   137  	if tracing.IsEnabled() {
   138  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.Delete")
   139  		defer func() {
   140  			sc := -1
   141  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   142  				sc = result.FutureAPI.Response().StatusCode
   143  			}
   144  			tracing.EndSpan(ctx, sc, err)
   145  		}()
   146  	}
   147  	if err := validation.Validate([]validation.Validation{
   148  		{TargetValue: resourceGroupName,
   149  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   150  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   151  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   152  		return result, validation.NewError("cdn.EndpointsClient", "Delete", err.Error())
   153  	}
   154  
   155  	req, err := client.DeletePreparer(ctx, resourceGroupName, profileName, endpointName)
   156  	if err != nil {
   157  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Delete", nil, "Failure preparing request")
   158  		return
   159  	}
   160  
   161  	result, err = client.DeleteSender(req)
   162  	if err != nil {
   163  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Delete", result.Response(), "Failure sending request")
   164  		return
   165  	}
   166  
   167  	return
   168  }
   169  
   170  // DeletePreparer prepares the Delete request.
   171  func (client EndpointsClient) DeletePreparer(ctx context.Context, resourceGroupName string, profileName string, endpointName string) (*http.Request, error) {
   172  	pathParameters := map[string]interface{}{
   173  		"endpointName":      autorest.Encode("path", endpointName),
   174  		"profileName":       autorest.Encode("path", profileName),
   175  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   176  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   177  	}
   178  
   179  	const APIVersion = "2021-06-01"
   180  	queryParameters := map[string]interface{}{
   181  		"api-version": APIVersion,
   182  	}
   183  
   184  	preparer := autorest.CreatePreparer(
   185  		autorest.AsDelete(),
   186  		autorest.WithBaseURL(client.BaseURI),
   187  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}", pathParameters),
   188  		autorest.WithQueryParameters(queryParameters))
   189  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   190  }
   191  
   192  // DeleteSender sends the Delete request. The method will close the
   193  // http.Response Body if it receives an error.
   194  func (client EndpointsClient) DeleteSender(req *http.Request) (future EndpointsDeleteFuture, err error) {
   195  	var resp *http.Response
   196  	future.FutureAPI = &azure.Future{}
   197  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   198  	if err != nil {
   199  		return
   200  	}
   201  	var azf azure.Future
   202  	azf, err = azure.NewFutureFromResponse(resp)
   203  	future.FutureAPI = &azf
   204  	future.Result = future.result
   205  	return
   206  }
   207  
   208  // DeleteResponder handles the response to the Delete request. The method always
   209  // closes the http.Response Body.
   210  func (client EndpointsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   211  	err = autorest.Respond(
   212  		resp,
   213  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   214  		autorest.ByClosing())
   215  	result.Response = resp
   216  	return
   217  }
   218  
   219  // Get gets an existing CDN endpoint with the specified endpoint name under the specified subscription, resource group
   220  // and profile.
   221  // Parameters:
   222  // resourceGroupName - name of the Resource group within the Azure subscription.
   223  // profileName - name of the CDN profile which is unique within the resource group.
   224  // endpointName - name of the endpoint under the profile which is unique globally.
   225  func (client EndpointsClient) Get(ctx context.Context, resourceGroupName string, profileName string, endpointName string) (result Endpoint, err error) {
   226  	if tracing.IsEnabled() {
   227  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.Get")
   228  		defer func() {
   229  			sc := -1
   230  			if result.Response.Response != nil {
   231  				sc = result.Response.Response.StatusCode
   232  			}
   233  			tracing.EndSpan(ctx, sc, err)
   234  		}()
   235  	}
   236  	if err := validation.Validate([]validation.Validation{
   237  		{TargetValue: resourceGroupName,
   238  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   239  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   240  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   241  		return result, validation.NewError("cdn.EndpointsClient", "Get", err.Error())
   242  	}
   243  
   244  	req, err := client.GetPreparer(ctx, resourceGroupName, profileName, endpointName)
   245  	if err != nil {
   246  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Get", nil, "Failure preparing request")
   247  		return
   248  	}
   249  
   250  	resp, err := client.GetSender(req)
   251  	if err != nil {
   252  		result.Response = autorest.Response{Response: resp}
   253  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Get", resp, "Failure sending request")
   254  		return
   255  	}
   256  
   257  	result, err = client.GetResponder(resp)
   258  	if err != nil {
   259  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Get", resp, "Failure responding to request")
   260  		return
   261  	}
   262  
   263  	return
   264  }
   265  
   266  // GetPreparer prepares the Get request.
   267  func (client EndpointsClient) GetPreparer(ctx context.Context, resourceGroupName string, profileName string, endpointName string) (*http.Request, error) {
   268  	pathParameters := map[string]interface{}{
   269  		"endpointName":      autorest.Encode("path", endpointName),
   270  		"profileName":       autorest.Encode("path", profileName),
   271  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   272  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   273  	}
   274  
   275  	const APIVersion = "2021-06-01"
   276  	queryParameters := map[string]interface{}{
   277  		"api-version": APIVersion,
   278  	}
   279  
   280  	preparer := autorest.CreatePreparer(
   281  		autorest.AsGet(),
   282  		autorest.WithBaseURL(client.BaseURI),
   283  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}", pathParameters),
   284  		autorest.WithQueryParameters(queryParameters))
   285  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   286  }
   287  
   288  // GetSender sends the Get request. The method will close the
   289  // http.Response Body if it receives an error.
   290  func (client EndpointsClient) GetSender(req *http.Request) (*http.Response, error) {
   291  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   292  }
   293  
   294  // GetResponder handles the response to the Get request. The method always
   295  // closes the http.Response Body.
   296  func (client EndpointsClient) GetResponder(resp *http.Response) (result Endpoint, err error) {
   297  	err = autorest.Respond(
   298  		resp,
   299  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   300  		autorest.ByUnmarshallingJSON(&result),
   301  		autorest.ByClosing())
   302  	result.Response = autorest.Response{Response: resp}
   303  	return
   304  }
   305  
   306  // ListByProfile lists existing CDN endpoints.
   307  // Parameters:
   308  // resourceGroupName - name of the Resource group within the Azure subscription.
   309  // profileName - name of the CDN profile which is unique within the resource group.
   310  func (client EndpointsClient) ListByProfile(ctx context.Context, resourceGroupName string, profileName string) (result EndpointListResultPage, err error) {
   311  	if tracing.IsEnabled() {
   312  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.ListByProfile")
   313  		defer func() {
   314  			sc := -1
   315  			if result.elr.Response.Response != nil {
   316  				sc = result.elr.Response.Response.StatusCode
   317  			}
   318  			tracing.EndSpan(ctx, sc, err)
   319  		}()
   320  	}
   321  	if err := validation.Validate([]validation.Validation{
   322  		{TargetValue: resourceGroupName,
   323  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   324  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   325  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   326  		return result, validation.NewError("cdn.EndpointsClient", "ListByProfile", err.Error())
   327  	}
   328  
   329  	result.fn = client.listByProfileNextResults
   330  	req, err := client.ListByProfilePreparer(ctx, resourceGroupName, profileName)
   331  	if err != nil {
   332  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "ListByProfile", nil, "Failure preparing request")
   333  		return
   334  	}
   335  
   336  	resp, err := client.ListByProfileSender(req)
   337  	if err != nil {
   338  		result.elr.Response = autorest.Response{Response: resp}
   339  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "ListByProfile", resp, "Failure sending request")
   340  		return
   341  	}
   342  
   343  	result.elr, err = client.ListByProfileResponder(resp)
   344  	if err != nil {
   345  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "ListByProfile", resp, "Failure responding to request")
   346  		return
   347  	}
   348  	if result.elr.hasNextLink() && result.elr.IsEmpty() {
   349  		err = result.NextWithContext(ctx)
   350  		return
   351  	}
   352  
   353  	return
   354  }
   355  
   356  // ListByProfilePreparer prepares the ListByProfile request.
   357  func (client EndpointsClient) ListByProfilePreparer(ctx context.Context, resourceGroupName string, profileName string) (*http.Request, error) {
   358  	pathParameters := map[string]interface{}{
   359  		"profileName":       autorest.Encode("path", profileName),
   360  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   361  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   362  	}
   363  
   364  	const APIVersion = "2021-06-01"
   365  	queryParameters := map[string]interface{}{
   366  		"api-version": APIVersion,
   367  	}
   368  
   369  	preparer := autorest.CreatePreparer(
   370  		autorest.AsGet(),
   371  		autorest.WithBaseURL(client.BaseURI),
   372  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints", pathParameters),
   373  		autorest.WithQueryParameters(queryParameters))
   374  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   375  }
   376  
   377  // ListByProfileSender sends the ListByProfile request. The method will close the
   378  // http.Response Body if it receives an error.
   379  func (client EndpointsClient) ListByProfileSender(req *http.Request) (*http.Response, error) {
   380  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   381  }
   382  
   383  // ListByProfileResponder handles the response to the ListByProfile request. The method always
   384  // closes the http.Response Body.
   385  func (client EndpointsClient) ListByProfileResponder(resp *http.Response) (result EndpointListResult, err error) {
   386  	err = autorest.Respond(
   387  		resp,
   388  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   389  		autorest.ByUnmarshallingJSON(&result),
   390  		autorest.ByClosing())
   391  	result.Response = autorest.Response{Response: resp}
   392  	return
   393  }
   394  
   395  // listByProfileNextResults retrieves the next set of results, if any.
   396  func (client EndpointsClient) listByProfileNextResults(ctx context.Context, lastResults EndpointListResult) (result EndpointListResult, err error) {
   397  	req, err := lastResults.endpointListResultPreparer(ctx)
   398  	if err != nil {
   399  		return result, autorest.NewErrorWithError(err, "cdn.EndpointsClient", "listByProfileNextResults", nil, "Failure preparing next results request")
   400  	}
   401  	if req == nil {
   402  		return
   403  	}
   404  	resp, err := client.ListByProfileSender(req)
   405  	if err != nil {
   406  		result.Response = autorest.Response{Response: resp}
   407  		return result, autorest.NewErrorWithError(err, "cdn.EndpointsClient", "listByProfileNextResults", resp, "Failure sending next results request")
   408  	}
   409  	result, err = client.ListByProfileResponder(resp)
   410  	if err != nil {
   411  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "listByProfileNextResults", resp, "Failure responding to next results request")
   412  	}
   413  	return
   414  }
   415  
   416  // ListByProfileComplete enumerates all values, automatically crossing page boundaries as required.
   417  func (client EndpointsClient) ListByProfileComplete(ctx context.Context, resourceGroupName string, profileName string) (result EndpointListResultIterator, err error) {
   418  	if tracing.IsEnabled() {
   419  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.ListByProfile")
   420  		defer func() {
   421  			sc := -1
   422  			if result.Response().Response.Response != nil {
   423  				sc = result.page.Response().Response.Response.StatusCode
   424  			}
   425  			tracing.EndSpan(ctx, sc, err)
   426  		}()
   427  	}
   428  	result.page, err = client.ListByProfile(ctx, resourceGroupName, profileName)
   429  	return
   430  }
   431  
   432  // ListResourceUsage checks the quota and usage of geo filters and custom domains under the given endpoint.
   433  // Parameters:
   434  // resourceGroupName - name of the Resource group within the Azure subscription.
   435  // profileName - name of the CDN profile which is unique within the resource group.
   436  // endpointName - name of the endpoint under the profile which is unique globally.
   437  func (client EndpointsClient) ListResourceUsage(ctx context.Context, resourceGroupName string, profileName string, endpointName string) (result ResourceUsageListResultPage, err error) {
   438  	if tracing.IsEnabled() {
   439  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.ListResourceUsage")
   440  		defer func() {
   441  			sc := -1
   442  			if result.rulr.Response.Response != nil {
   443  				sc = result.rulr.Response.Response.StatusCode
   444  			}
   445  			tracing.EndSpan(ctx, sc, err)
   446  		}()
   447  	}
   448  	if err := validation.Validate([]validation.Validation{
   449  		{TargetValue: resourceGroupName,
   450  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   451  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   452  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   453  		return result, validation.NewError("cdn.EndpointsClient", "ListResourceUsage", err.Error())
   454  	}
   455  
   456  	result.fn = client.listResourceUsageNextResults
   457  	req, err := client.ListResourceUsagePreparer(ctx, resourceGroupName, profileName, endpointName)
   458  	if err != nil {
   459  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "ListResourceUsage", nil, "Failure preparing request")
   460  		return
   461  	}
   462  
   463  	resp, err := client.ListResourceUsageSender(req)
   464  	if err != nil {
   465  		result.rulr.Response = autorest.Response{Response: resp}
   466  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "ListResourceUsage", resp, "Failure sending request")
   467  		return
   468  	}
   469  
   470  	result.rulr, err = client.ListResourceUsageResponder(resp)
   471  	if err != nil {
   472  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "ListResourceUsage", resp, "Failure responding to request")
   473  		return
   474  	}
   475  	if result.rulr.hasNextLink() && result.rulr.IsEmpty() {
   476  		err = result.NextWithContext(ctx)
   477  		return
   478  	}
   479  
   480  	return
   481  }
   482  
   483  // ListResourceUsagePreparer prepares the ListResourceUsage request.
   484  func (client EndpointsClient) ListResourceUsagePreparer(ctx context.Context, resourceGroupName string, profileName string, endpointName string) (*http.Request, error) {
   485  	pathParameters := map[string]interface{}{
   486  		"endpointName":      autorest.Encode("path", endpointName),
   487  		"profileName":       autorest.Encode("path", profileName),
   488  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   489  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   490  	}
   491  
   492  	const APIVersion = "2021-06-01"
   493  	queryParameters := map[string]interface{}{
   494  		"api-version": APIVersion,
   495  	}
   496  
   497  	preparer := autorest.CreatePreparer(
   498  		autorest.AsPost(),
   499  		autorest.WithBaseURL(client.BaseURI),
   500  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/checkResourceUsage", pathParameters),
   501  		autorest.WithQueryParameters(queryParameters))
   502  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   503  }
   504  
   505  // ListResourceUsageSender sends the ListResourceUsage request. The method will close the
   506  // http.Response Body if it receives an error.
   507  func (client EndpointsClient) ListResourceUsageSender(req *http.Request) (*http.Response, error) {
   508  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   509  }
   510  
   511  // ListResourceUsageResponder handles the response to the ListResourceUsage request. The method always
   512  // closes the http.Response Body.
   513  func (client EndpointsClient) ListResourceUsageResponder(resp *http.Response) (result ResourceUsageListResult, err error) {
   514  	err = autorest.Respond(
   515  		resp,
   516  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   517  		autorest.ByUnmarshallingJSON(&result),
   518  		autorest.ByClosing())
   519  	result.Response = autorest.Response{Response: resp}
   520  	return
   521  }
   522  
   523  // listResourceUsageNextResults retrieves the next set of results, if any.
   524  func (client EndpointsClient) listResourceUsageNextResults(ctx context.Context, lastResults ResourceUsageListResult) (result ResourceUsageListResult, err error) {
   525  	req, err := lastResults.resourceUsageListResultPreparer(ctx)
   526  	if err != nil {
   527  		return result, autorest.NewErrorWithError(err, "cdn.EndpointsClient", "listResourceUsageNextResults", nil, "Failure preparing next results request")
   528  	}
   529  	if req == nil {
   530  		return
   531  	}
   532  	resp, err := client.ListResourceUsageSender(req)
   533  	if err != nil {
   534  		result.Response = autorest.Response{Response: resp}
   535  		return result, autorest.NewErrorWithError(err, "cdn.EndpointsClient", "listResourceUsageNextResults", resp, "Failure sending next results request")
   536  	}
   537  	result, err = client.ListResourceUsageResponder(resp)
   538  	if err != nil {
   539  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "listResourceUsageNextResults", resp, "Failure responding to next results request")
   540  	}
   541  	return
   542  }
   543  
   544  // ListResourceUsageComplete enumerates all values, automatically crossing page boundaries as required.
   545  func (client EndpointsClient) ListResourceUsageComplete(ctx context.Context, resourceGroupName string, profileName string, endpointName string) (result ResourceUsageListResultIterator, err error) {
   546  	if tracing.IsEnabled() {
   547  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.ListResourceUsage")
   548  		defer func() {
   549  			sc := -1
   550  			if result.Response().Response.Response != nil {
   551  				sc = result.page.Response().Response.Response.StatusCode
   552  			}
   553  			tracing.EndSpan(ctx, sc, err)
   554  		}()
   555  	}
   556  	result.page, err = client.ListResourceUsage(ctx, resourceGroupName, profileName, endpointName)
   557  	return
   558  }
   559  
   560  // LoadContent pre-loads a content to CDN. Available for Verizon Profiles.
   561  // Parameters:
   562  // resourceGroupName - name of the Resource group within the Azure subscription.
   563  // profileName - name of the CDN profile which is unique within the resource group.
   564  // endpointName - name of the endpoint under the profile which is unique globally.
   565  // contentFilePaths - the path to the content to be loaded. Path should be a full URL, e.g.
   566  // ‘/pictures/city.png' which loads a single file
   567  func (client EndpointsClient) LoadContent(ctx context.Context, resourceGroupName string, profileName string, endpointName string, contentFilePaths LoadParameters) (result EndpointsLoadContentFuture, err error) {
   568  	if tracing.IsEnabled() {
   569  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.LoadContent")
   570  		defer func() {
   571  			sc := -1
   572  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   573  				sc = result.FutureAPI.Response().StatusCode
   574  			}
   575  			tracing.EndSpan(ctx, sc, err)
   576  		}()
   577  	}
   578  	if err := validation.Validate([]validation.Validation{
   579  		{TargetValue: resourceGroupName,
   580  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   581  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   582  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   583  		{TargetValue: contentFilePaths,
   584  			Constraints: []validation.Constraint{{Target: "contentFilePaths.ContentPaths", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   585  		return result, validation.NewError("cdn.EndpointsClient", "LoadContent", err.Error())
   586  	}
   587  
   588  	req, err := client.LoadContentPreparer(ctx, resourceGroupName, profileName, endpointName, contentFilePaths)
   589  	if err != nil {
   590  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "LoadContent", nil, "Failure preparing request")
   591  		return
   592  	}
   593  
   594  	result, err = client.LoadContentSender(req)
   595  	if err != nil {
   596  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "LoadContent", result.Response(), "Failure sending request")
   597  		return
   598  	}
   599  
   600  	return
   601  }
   602  
   603  // LoadContentPreparer prepares the LoadContent request.
   604  func (client EndpointsClient) LoadContentPreparer(ctx context.Context, resourceGroupName string, profileName string, endpointName string, contentFilePaths LoadParameters) (*http.Request, error) {
   605  	pathParameters := map[string]interface{}{
   606  		"endpointName":      autorest.Encode("path", endpointName),
   607  		"profileName":       autorest.Encode("path", profileName),
   608  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   609  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   610  	}
   611  
   612  	const APIVersion = "2021-06-01"
   613  	queryParameters := map[string]interface{}{
   614  		"api-version": APIVersion,
   615  	}
   616  
   617  	preparer := autorest.CreatePreparer(
   618  		autorest.AsContentType("application/json; charset=utf-8"),
   619  		autorest.AsPost(),
   620  		autorest.WithBaseURL(client.BaseURI),
   621  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/load", pathParameters),
   622  		autorest.WithJSON(contentFilePaths),
   623  		autorest.WithQueryParameters(queryParameters))
   624  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   625  }
   626  
   627  // LoadContentSender sends the LoadContent request. The method will close the
   628  // http.Response Body if it receives an error.
   629  func (client EndpointsClient) LoadContentSender(req *http.Request) (future EndpointsLoadContentFuture, err error) {
   630  	var resp *http.Response
   631  	future.FutureAPI = &azure.Future{}
   632  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   633  	if err != nil {
   634  		return
   635  	}
   636  	var azf azure.Future
   637  	azf, err = azure.NewFutureFromResponse(resp)
   638  	future.FutureAPI = &azf
   639  	future.Result = future.result
   640  	return
   641  }
   642  
   643  // LoadContentResponder handles the response to the LoadContent request. The method always
   644  // closes the http.Response Body.
   645  func (client EndpointsClient) LoadContentResponder(resp *http.Response) (result autorest.Response, err error) {
   646  	err = autorest.Respond(
   647  		resp,
   648  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   649  		autorest.ByClosing())
   650  	result.Response = resp
   651  	return
   652  }
   653  
   654  // PurgeContent removes a content from CDN.
   655  // Parameters:
   656  // resourceGroupName - name of the Resource group within the Azure subscription.
   657  // profileName - name of the CDN profile which is unique within the resource group.
   658  // endpointName - name of the endpoint under the profile which is unique globally.
   659  // contentFilePaths - the path to the content to be purged. Path can be a full URL, e.g. '/pictures/city.png'
   660  // which removes a single file, or a directory with a wildcard, e.g. '/pictures/*' which removes all folders
   661  // and files in the directory.
   662  func (client EndpointsClient) PurgeContent(ctx context.Context, resourceGroupName string, profileName string, endpointName string, contentFilePaths PurgeParameters) (result EndpointsPurgeContentFuture, err error) {
   663  	if tracing.IsEnabled() {
   664  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.PurgeContent")
   665  		defer func() {
   666  			sc := -1
   667  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   668  				sc = result.FutureAPI.Response().StatusCode
   669  			}
   670  			tracing.EndSpan(ctx, sc, err)
   671  		}()
   672  	}
   673  	if err := validation.Validate([]validation.Validation{
   674  		{TargetValue: resourceGroupName,
   675  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   676  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   677  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
   678  		{TargetValue: contentFilePaths,
   679  			Constraints: []validation.Constraint{{Target: "contentFilePaths.ContentPaths", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
   680  		return result, validation.NewError("cdn.EndpointsClient", "PurgeContent", err.Error())
   681  	}
   682  
   683  	req, err := client.PurgeContentPreparer(ctx, resourceGroupName, profileName, endpointName, contentFilePaths)
   684  	if err != nil {
   685  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "PurgeContent", nil, "Failure preparing request")
   686  		return
   687  	}
   688  
   689  	result, err = client.PurgeContentSender(req)
   690  	if err != nil {
   691  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "PurgeContent", result.Response(), "Failure sending request")
   692  		return
   693  	}
   694  
   695  	return
   696  }
   697  
   698  // PurgeContentPreparer prepares the PurgeContent request.
   699  func (client EndpointsClient) PurgeContentPreparer(ctx context.Context, resourceGroupName string, profileName string, endpointName string, contentFilePaths PurgeParameters) (*http.Request, error) {
   700  	pathParameters := map[string]interface{}{
   701  		"endpointName":      autorest.Encode("path", endpointName),
   702  		"profileName":       autorest.Encode("path", profileName),
   703  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   704  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   705  	}
   706  
   707  	const APIVersion = "2021-06-01"
   708  	queryParameters := map[string]interface{}{
   709  		"api-version": APIVersion,
   710  	}
   711  
   712  	preparer := autorest.CreatePreparer(
   713  		autorest.AsContentType("application/json; charset=utf-8"),
   714  		autorest.AsPost(),
   715  		autorest.WithBaseURL(client.BaseURI),
   716  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/purge", pathParameters),
   717  		autorest.WithJSON(contentFilePaths),
   718  		autorest.WithQueryParameters(queryParameters))
   719  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   720  }
   721  
   722  // PurgeContentSender sends the PurgeContent request. The method will close the
   723  // http.Response Body if it receives an error.
   724  func (client EndpointsClient) PurgeContentSender(req *http.Request) (future EndpointsPurgeContentFuture, err error) {
   725  	var resp *http.Response
   726  	future.FutureAPI = &azure.Future{}
   727  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   728  	if err != nil {
   729  		return
   730  	}
   731  	var azf azure.Future
   732  	azf, err = azure.NewFutureFromResponse(resp)
   733  	future.FutureAPI = &azf
   734  	future.Result = future.result
   735  	return
   736  }
   737  
   738  // PurgeContentResponder handles the response to the PurgeContent request. The method always
   739  // closes the http.Response Body.
   740  func (client EndpointsClient) PurgeContentResponder(resp *http.Response) (result autorest.Response, err error) {
   741  	err = autorest.Respond(
   742  		resp,
   743  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   744  		autorest.ByClosing())
   745  	result.Response = resp
   746  	return
   747  }
   748  
   749  // Start starts an existing CDN endpoint that is on a stopped state.
   750  // Parameters:
   751  // resourceGroupName - name of the Resource group within the Azure subscription.
   752  // profileName - name of the CDN profile which is unique within the resource group.
   753  // endpointName - name of the endpoint under the profile which is unique globally.
   754  func (client EndpointsClient) Start(ctx context.Context, resourceGroupName string, profileName string, endpointName string) (result EndpointsStartFuture, err error) {
   755  	if tracing.IsEnabled() {
   756  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.Start")
   757  		defer func() {
   758  			sc := -1
   759  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   760  				sc = result.FutureAPI.Response().StatusCode
   761  			}
   762  			tracing.EndSpan(ctx, sc, err)
   763  		}()
   764  	}
   765  	if err := validation.Validate([]validation.Validation{
   766  		{TargetValue: resourceGroupName,
   767  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   768  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   769  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   770  		return result, validation.NewError("cdn.EndpointsClient", "Start", err.Error())
   771  	}
   772  
   773  	req, err := client.StartPreparer(ctx, resourceGroupName, profileName, endpointName)
   774  	if err != nil {
   775  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Start", nil, "Failure preparing request")
   776  		return
   777  	}
   778  
   779  	result, err = client.StartSender(req)
   780  	if err != nil {
   781  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Start", result.Response(), "Failure sending request")
   782  		return
   783  	}
   784  
   785  	return
   786  }
   787  
   788  // StartPreparer prepares the Start request.
   789  func (client EndpointsClient) StartPreparer(ctx context.Context, resourceGroupName string, profileName string, endpointName string) (*http.Request, error) {
   790  	pathParameters := map[string]interface{}{
   791  		"endpointName":      autorest.Encode("path", endpointName),
   792  		"profileName":       autorest.Encode("path", profileName),
   793  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   794  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   795  	}
   796  
   797  	const APIVersion = "2021-06-01"
   798  	queryParameters := map[string]interface{}{
   799  		"api-version": APIVersion,
   800  	}
   801  
   802  	preparer := autorest.CreatePreparer(
   803  		autorest.AsPost(),
   804  		autorest.WithBaseURL(client.BaseURI),
   805  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/start", pathParameters),
   806  		autorest.WithQueryParameters(queryParameters))
   807  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   808  }
   809  
   810  // StartSender sends the Start request. The method will close the
   811  // http.Response Body if it receives an error.
   812  func (client EndpointsClient) StartSender(req *http.Request) (future EndpointsStartFuture, err error) {
   813  	var resp *http.Response
   814  	future.FutureAPI = &azure.Future{}
   815  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   816  	if err != nil {
   817  		return
   818  	}
   819  	var azf azure.Future
   820  	azf, err = azure.NewFutureFromResponse(resp)
   821  	future.FutureAPI = &azf
   822  	future.Result = future.result
   823  	return
   824  }
   825  
   826  // StartResponder handles the response to the Start request. The method always
   827  // closes the http.Response Body.
   828  func (client EndpointsClient) StartResponder(resp *http.Response) (result Endpoint, err error) {
   829  	err = autorest.Respond(
   830  		resp,
   831  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   832  		autorest.ByUnmarshallingJSON(&result),
   833  		autorest.ByClosing())
   834  	result.Response = autorest.Response{Response: resp}
   835  	return
   836  }
   837  
   838  // Stop stops an existing running CDN endpoint.
   839  // Parameters:
   840  // resourceGroupName - name of the Resource group within the Azure subscription.
   841  // profileName - name of the CDN profile which is unique within the resource group.
   842  // endpointName - name of the endpoint under the profile which is unique globally.
   843  func (client EndpointsClient) Stop(ctx context.Context, resourceGroupName string, profileName string, endpointName string) (result EndpointsStopFuture, err error) {
   844  	if tracing.IsEnabled() {
   845  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.Stop")
   846  		defer func() {
   847  			sc := -1
   848  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   849  				sc = result.FutureAPI.Response().StatusCode
   850  			}
   851  			tracing.EndSpan(ctx, sc, err)
   852  		}()
   853  	}
   854  	if err := validation.Validate([]validation.Validation{
   855  		{TargetValue: resourceGroupName,
   856  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   857  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   858  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   859  		return result, validation.NewError("cdn.EndpointsClient", "Stop", err.Error())
   860  	}
   861  
   862  	req, err := client.StopPreparer(ctx, resourceGroupName, profileName, endpointName)
   863  	if err != nil {
   864  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Stop", nil, "Failure preparing request")
   865  		return
   866  	}
   867  
   868  	result, err = client.StopSender(req)
   869  	if err != nil {
   870  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Stop", result.Response(), "Failure sending request")
   871  		return
   872  	}
   873  
   874  	return
   875  }
   876  
   877  // StopPreparer prepares the Stop request.
   878  func (client EndpointsClient) StopPreparer(ctx context.Context, resourceGroupName string, profileName string, endpointName string) (*http.Request, error) {
   879  	pathParameters := map[string]interface{}{
   880  		"endpointName":      autorest.Encode("path", endpointName),
   881  		"profileName":       autorest.Encode("path", profileName),
   882  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   883  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   884  	}
   885  
   886  	const APIVersion = "2021-06-01"
   887  	queryParameters := map[string]interface{}{
   888  		"api-version": APIVersion,
   889  	}
   890  
   891  	preparer := autorest.CreatePreparer(
   892  		autorest.AsPost(),
   893  		autorest.WithBaseURL(client.BaseURI),
   894  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/stop", pathParameters),
   895  		autorest.WithQueryParameters(queryParameters))
   896  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   897  }
   898  
   899  // StopSender sends the Stop request. The method will close the
   900  // http.Response Body if it receives an error.
   901  func (client EndpointsClient) StopSender(req *http.Request) (future EndpointsStopFuture, err error) {
   902  	var resp *http.Response
   903  	future.FutureAPI = &azure.Future{}
   904  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   905  	if err != nil {
   906  		return
   907  	}
   908  	var azf azure.Future
   909  	azf, err = azure.NewFutureFromResponse(resp)
   910  	future.FutureAPI = &azf
   911  	future.Result = future.result
   912  	return
   913  }
   914  
   915  // StopResponder handles the response to the Stop request. The method always
   916  // closes the http.Response Body.
   917  func (client EndpointsClient) StopResponder(resp *http.Response) (result Endpoint, err error) {
   918  	err = autorest.Respond(
   919  		resp,
   920  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   921  		autorest.ByUnmarshallingJSON(&result),
   922  		autorest.ByClosing())
   923  	result.Response = autorest.Response{Response: resp}
   924  	return
   925  }
   926  
   927  // Update updates an existing CDN endpoint with the specified endpoint name under the specified subscription, resource
   928  // group and profile. Only tags can be updated after creating an endpoint. To update origins, use the Update Origin
   929  // operation. To update origin groups, use the Update Origin group operation. To update custom domains, use the Update
   930  // Custom Domain operation.
   931  // Parameters:
   932  // resourceGroupName - name of the Resource group within the Azure subscription.
   933  // profileName - name of the CDN profile which is unique within the resource group.
   934  // endpointName - name of the endpoint under the profile which is unique globally.
   935  // endpointUpdateProperties - endpoint update properties
   936  func (client EndpointsClient) Update(ctx context.Context, resourceGroupName string, profileName string, endpointName string, endpointUpdateProperties EndpointUpdateParameters) (result EndpointsUpdateFuture, err error) {
   937  	if tracing.IsEnabled() {
   938  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.Update")
   939  		defer func() {
   940  			sc := -1
   941  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   942  				sc = result.FutureAPI.Response().StatusCode
   943  			}
   944  			tracing.EndSpan(ctx, sc, err)
   945  		}()
   946  	}
   947  	if err := validation.Validate([]validation.Validation{
   948  		{TargetValue: resourceGroupName,
   949  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   950  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   951  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   952  		return result, validation.NewError("cdn.EndpointsClient", "Update", err.Error())
   953  	}
   954  
   955  	req, err := client.UpdatePreparer(ctx, resourceGroupName, profileName, endpointName, endpointUpdateProperties)
   956  	if err != nil {
   957  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Update", nil, "Failure preparing request")
   958  		return
   959  	}
   960  
   961  	result, err = client.UpdateSender(req)
   962  	if err != nil {
   963  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "Update", result.Response(), "Failure sending request")
   964  		return
   965  	}
   966  
   967  	return
   968  }
   969  
   970  // UpdatePreparer prepares the Update request.
   971  func (client EndpointsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, profileName string, endpointName string, endpointUpdateProperties EndpointUpdateParameters) (*http.Request, error) {
   972  	pathParameters := map[string]interface{}{
   973  		"endpointName":      autorest.Encode("path", endpointName),
   974  		"profileName":       autorest.Encode("path", profileName),
   975  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   976  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   977  	}
   978  
   979  	const APIVersion = "2021-06-01"
   980  	queryParameters := map[string]interface{}{
   981  		"api-version": APIVersion,
   982  	}
   983  
   984  	preparer := autorest.CreatePreparer(
   985  		autorest.AsContentType("application/json; charset=utf-8"),
   986  		autorest.AsPatch(),
   987  		autorest.WithBaseURL(client.BaseURI),
   988  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}", pathParameters),
   989  		autorest.WithJSON(endpointUpdateProperties),
   990  		autorest.WithQueryParameters(queryParameters))
   991  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   992  }
   993  
   994  // UpdateSender sends the Update request. The method will close the
   995  // http.Response Body if it receives an error.
   996  func (client EndpointsClient) UpdateSender(req *http.Request) (future EndpointsUpdateFuture, err error) {
   997  	var resp *http.Response
   998  	future.FutureAPI = &azure.Future{}
   999  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
  1000  	if err != nil {
  1001  		return
  1002  	}
  1003  	var azf azure.Future
  1004  	azf, err = azure.NewFutureFromResponse(resp)
  1005  	future.FutureAPI = &azf
  1006  	future.Result = future.result
  1007  	return
  1008  }
  1009  
  1010  // UpdateResponder handles the response to the Update request. The method always
  1011  // closes the http.Response Body.
  1012  func (client EndpointsClient) UpdateResponder(resp *http.Response) (result Endpoint, err error) {
  1013  	err = autorest.Respond(
  1014  		resp,
  1015  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
  1016  		autorest.ByUnmarshallingJSON(&result),
  1017  		autorest.ByClosing())
  1018  	result.Response = autorest.Response{Response: resp}
  1019  	return
  1020  }
  1021  
  1022  // ValidateCustomDomain validates the custom domain mapping to ensure it maps to the correct CDN endpoint in DNS.
  1023  // Parameters:
  1024  // resourceGroupName - name of the Resource group within the Azure subscription.
  1025  // profileName - name of the CDN profile which is unique within the resource group.
  1026  // endpointName - name of the endpoint under the profile which is unique globally.
  1027  // customDomainProperties - custom domain to be validated.
  1028  func (client EndpointsClient) ValidateCustomDomain(ctx context.Context, resourceGroupName string, profileName string, endpointName string, customDomainProperties ValidateCustomDomainInput) (result ValidateCustomDomainOutput, err error) {
  1029  	if tracing.IsEnabled() {
  1030  		ctx = tracing.StartSpan(ctx, fqdn+"/EndpointsClient.ValidateCustomDomain")
  1031  		defer func() {
  1032  			sc := -1
  1033  			if result.Response.Response != nil {
  1034  				sc = result.Response.Response.StatusCode
  1035  			}
  1036  			tracing.EndSpan(ctx, sc, err)
  1037  		}()
  1038  	}
  1039  	if err := validation.Validate([]validation.Validation{
  1040  		{TargetValue: resourceGroupName,
  1041  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
  1042  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
  1043  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
  1044  		{TargetValue: customDomainProperties,
  1045  			Constraints: []validation.Constraint{{Target: "customDomainProperties.HostName", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
  1046  		return result, validation.NewError("cdn.EndpointsClient", "ValidateCustomDomain", err.Error())
  1047  	}
  1048  
  1049  	req, err := client.ValidateCustomDomainPreparer(ctx, resourceGroupName, profileName, endpointName, customDomainProperties)
  1050  	if err != nil {
  1051  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "ValidateCustomDomain", nil, "Failure preparing request")
  1052  		return
  1053  	}
  1054  
  1055  	resp, err := client.ValidateCustomDomainSender(req)
  1056  	if err != nil {
  1057  		result.Response = autorest.Response{Response: resp}
  1058  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "ValidateCustomDomain", resp, "Failure sending request")
  1059  		return
  1060  	}
  1061  
  1062  	result, err = client.ValidateCustomDomainResponder(resp)
  1063  	if err != nil {
  1064  		err = autorest.NewErrorWithError(err, "cdn.EndpointsClient", "ValidateCustomDomain", resp, "Failure responding to request")
  1065  		return
  1066  	}
  1067  
  1068  	return
  1069  }
  1070  
  1071  // ValidateCustomDomainPreparer prepares the ValidateCustomDomain request.
  1072  func (client EndpointsClient) ValidateCustomDomainPreparer(ctx context.Context, resourceGroupName string, profileName string, endpointName string, customDomainProperties ValidateCustomDomainInput) (*http.Request, error) {
  1073  	pathParameters := map[string]interface{}{
  1074  		"endpointName":      autorest.Encode("path", endpointName),
  1075  		"profileName":       autorest.Encode("path", profileName),
  1076  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
  1077  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
  1078  	}
  1079  
  1080  	const APIVersion = "2021-06-01"
  1081  	queryParameters := map[string]interface{}{
  1082  		"api-version": APIVersion,
  1083  	}
  1084  
  1085  	preparer := autorest.CreatePreparer(
  1086  		autorest.AsContentType("application/json; charset=utf-8"),
  1087  		autorest.AsPost(),
  1088  		autorest.WithBaseURL(client.BaseURI),
  1089  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/validateCustomDomain", pathParameters),
  1090  		autorest.WithJSON(customDomainProperties),
  1091  		autorest.WithQueryParameters(queryParameters))
  1092  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1093  }
  1094  
  1095  // ValidateCustomDomainSender sends the ValidateCustomDomain request. The method will close the
  1096  // http.Response Body if it receives an error.
  1097  func (client EndpointsClient) ValidateCustomDomainSender(req *http.Request) (*http.Response, error) {
  1098  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
  1099  }
  1100  
  1101  // ValidateCustomDomainResponder handles the response to the ValidateCustomDomain request. The method always
  1102  // closes the http.Response Body.
  1103  func (client EndpointsClient) ValidateCustomDomainResponder(resp *http.Response) (result ValidateCustomDomainOutput, err error) {
  1104  	err = autorest.Respond(
  1105  		resp,
  1106  		azure.WithErrorUnlessStatusCode(http.StatusOK),
  1107  		autorest.ByUnmarshallingJSON(&result),
  1108  		autorest.ByClosing())
  1109  	result.Response = autorest.Response{Response: resp}
  1110  	return
  1111  }
  1112  

View as plain text