...

Source file src/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-05-01/network/ddoscustompolicies.go

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

     1  package network
     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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // DdosCustomPoliciesClient is the network Client
    18  type DdosCustomPoliciesClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewDdosCustomPoliciesClient creates an instance of the DdosCustomPoliciesClient client.
    23  func NewDdosCustomPoliciesClient(subscriptionID string) DdosCustomPoliciesClient {
    24  	return NewDdosCustomPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewDdosCustomPoliciesClientWithBaseURI creates an instance of the DdosCustomPoliciesClient client using a custom
    28  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    29  // stack).
    30  func NewDdosCustomPoliciesClientWithBaseURI(baseURI string, subscriptionID string) DdosCustomPoliciesClient {
    31  	return DdosCustomPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate creates or updates a DDoS custom policy.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group.
    37  // ddosCustomPolicyName - the name of the DDoS custom policy.
    38  // parameters - parameters supplied to the create or update operation.
    39  func (client DdosCustomPoliciesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, parameters DdosCustomPolicy) (result DdosCustomPoliciesCreateOrUpdateFuture, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/DdosCustomPoliciesClient.CreateOrUpdate")
    42  		defer func() {
    43  			sc := -1
    44  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    45  				sc = result.FutureAPI.Response().StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, ddosCustomPolicyName, parameters)
    51  	if err != nil {
    52  		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request")
    53  		return
    54  	}
    55  
    56  	result, err = client.CreateOrUpdateSender(req)
    57  	if err != nil {
    58  		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    59  		return
    60  	}
    61  
    62  	return
    63  }
    64  
    65  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    66  func (client DdosCustomPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, parameters DdosCustomPolicy) (*http.Request, error) {
    67  	pathParameters := map[string]interface{}{
    68  		"ddosCustomPolicyName": autorest.Encode("path", ddosCustomPolicyName),
    69  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
    70  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
    71  	}
    72  
    73  	const APIVersion = "2021-05-01"
    74  	queryParameters := map[string]interface{}{
    75  		"api-version": APIVersion,
    76  	}
    77  
    78  	parameters.Etag = nil
    79  	preparer := autorest.CreatePreparer(
    80  		autorest.AsContentType("application/json; charset=utf-8"),
    81  		autorest.AsPut(),
    82  		autorest.WithBaseURL(client.BaseURI),
    83  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/ddosCustomPolicies/{ddosCustomPolicyName}", pathParameters),
    84  		autorest.WithJSON(parameters),
    85  		autorest.WithQueryParameters(queryParameters))
    86  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    87  }
    88  
    89  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
    90  // http.Response Body if it receives an error.
    91  func (client DdosCustomPoliciesClient) CreateOrUpdateSender(req *http.Request) (future DdosCustomPoliciesCreateOrUpdateFuture, err error) {
    92  	var resp *http.Response
    93  	future.FutureAPI = &azure.Future{}
    94  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
    95  	if err != nil {
    96  		return
    97  	}
    98  	var azf azure.Future
    99  	azf, err = azure.NewFutureFromResponse(resp)
   100  	future.FutureAPI = &azf
   101  	future.Result = future.result
   102  	return
   103  }
   104  
   105  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   106  // closes the http.Response Body.
   107  func (client DdosCustomPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result DdosCustomPolicy, err error) {
   108  	err = autorest.Respond(
   109  		resp,
   110  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   111  		autorest.ByUnmarshallingJSON(&result),
   112  		autorest.ByClosing())
   113  	result.Response = autorest.Response{Response: resp}
   114  	return
   115  }
   116  
   117  // Delete deletes the specified DDoS custom policy.
   118  // Parameters:
   119  // resourceGroupName - the name of the resource group.
   120  // ddosCustomPolicyName - the name of the DDoS custom policy.
   121  func (client DdosCustomPoliciesClient) Delete(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string) (result DdosCustomPoliciesDeleteFuture, err error) {
   122  	if tracing.IsEnabled() {
   123  		ctx = tracing.StartSpan(ctx, fqdn+"/DdosCustomPoliciesClient.Delete")
   124  		defer func() {
   125  			sc := -1
   126  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   127  				sc = result.FutureAPI.Response().StatusCode
   128  			}
   129  			tracing.EndSpan(ctx, sc, err)
   130  		}()
   131  	}
   132  	req, err := client.DeletePreparer(ctx, resourceGroupName, ddosCustomPolicyName)
   133  	if err != nil {
   134  		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "Delete", nil, "Failure preparing request")
   135  		return
   136  	}
   137  
   138  	result, err = client.DeleteSender(req)
   139  	if err != nil {
   140  		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "Delete", result.Response(), "Failure sending request")
   141  		return
   142  	}
   143  
   144  	return
   145  }
   146  
   147  // DeletePreparer prepares the Delete request.
   148  func (client DdosCustomPoliciesClient) DeletePreparer(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string) (*http.Request, error) {
   149  	pathParameters := map[string]interface{}{
   150  		"ddosCustomPolicyName": autorest.Encode("path", ddosCustomPolicyName),
   151  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
   152  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   153  	}
   154  
   155  	const APIVersion = "2021-05-01"
   156  	queryParameters := map[string]interface{}{
   157  		"api-version": APIVersion,
   158  	}
   159  
   160  	preparer := autorest.CreatePreparer(
   161  		autorest.AsDelete(),
   162  		autorest.WithBaseURL(client.BaseURI),
   163  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/ddosCustomPolicies/{ddosCustomPolicyName}", pathParameters),
   164  		autorest.WithQueryParameters(queryParameters))
   165  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   166  }
   167  
   168  // DeleteSender sends the Delete request. The method will close the
   169  // http.Response Body if it receives an error.
   170  func (client DdosCustomPoliciesClient) DeleteSender(req *http.Request) (future DdosCustomPoliciesDeleteFuture, err error) {
   171  	var resp *http.Response
   172  	future.FutureAPI = &azure.Future{}
   173  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   174  	if err != nil {
   175  		return
   176  	}
   177  	var azf azure.Future
   178  	azf, err = azure.NewFutureFromResponse(resp)
   179  	future.FutureAPI = &azf
   180  	future.Result = future.result
   181  	return
   182  }
   183  
   184  // DeleteResponder handles the response to the Delete request. The method always
   185  // closes the http.Response Body.
   186  func (client DdosCustomPoliciesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   187  	err = autorest.Respond(
   188  		resp,
   189  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   190  		autorest.ByClosing())
   191  	result.Response = resp
   192  	return
   193  }
   194  
   195  // Get gets information about the specified DDoS custom policy.
   196  // Parameters:
   197  // resourceGroupName - the name of the resource group.
   198  // ddosCustomPolicyName - the name of the DDoS custom policy.
   199  func (client DdosCustomPoliciesClient) Get(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string) (result DdosCustomPolicy, err error) {
   200  	if tracing.IsEnabled() {
   201  		ctx = tracing.StartSpan(ctx, fqdn+"/DdosCustomPoliciesClient.Get")
   202  		defer func() {
   203  			sc := -1
   204  			if result.Response.Response != nil {
   205  				sc = result.Response.Response.StatusCode
   206  			}
   207  			tracing.EndSpan(ctx, sc, err)
   208  		}()
   209  	}
   210  	req, err := client.GetPreparer(ctx, resourceGroupName, ddosCustomPolicyName)
   211  	if err != nil {
   212  		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "Get", nil, "Failure preparing request")
   213  		return
   214  	}
   215  
   216  	resp, err := client.GetSender(req)
   217  	if err != nil {
   218  		result.Response = autorest.Response{Response: resp}
   219  		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "Get", resp, "Failure sending request")
   220  		return
   221  	}
   222  
   223  	result, err = client.GetResponder(resp)
   224  	if err != nil {
   225  		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "Get", resp, "Failure responding to request")
   226  		return
   227  	}
   228  
   229  	return
   230  }
   231  
   232  // GetPreparer prepares the Get request.
   233  func (client DdosCustomPoliciesClient) GetPreparer(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string) (*http.Request, error) {
   234  	pathParameters := map[string]interface{}{
   235  		"ddosCustomPolicyName": autorest.Encode("path", ddosCustomPolicyName),
   236  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
   237  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   238  	}
   239  
   240  	const APIVersion = "2021-05-01"
   241  	queryParameters := map[string]interface{}{
   242  		"api-version": APIVersion,
   243  	}
   244  
   245  	preparer := autorest.CreatePreparer(
   246  		autorest.AsGet(),
   247  		autorest.WithBaseURL(client.BaseURI),
   248  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/ddosCustomPolicies/{ddosCustomPolicyName}", pathParameters),
   249  		autorest.WithQueryParameters(queryParameters))
   250  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   251  }
   252  
   253  // GetSender sends the Get request. The method will close the
   254  // http.Response Body if it receives an error.
   255  func (client DdosCustomPoliciesClient) GetSender(req *http.Request) (*http.Response, error) {
   256  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   257  }
   258  
   259  // GetResponder handles the response to the Get request. The method always
   260  // closes the http.Response Body.
   261  func (client DdosCustomPoliciesClient) GetResponder(resp *http.Response) (result DdosCustomPolicy, err error) {
   262  	err = autorest.Respond(
   263  		resp,
   264  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   265  		autorest.ByUnmarshallingJSON(&result),
   266  		autorest.ByClosing())
   267  	result.Response = autorest.Response{Response: resp}
   268  	return
   269  }
   270  
   271  // UpdateTags update a DDoS custom policy tags.
   272  // Parameters:
   273  // resourceGroupName - the name of the resource group.
   274  // ddosCustomPolicyName - the name of the DDoS custom policy.
   275  // parameters - parameters supplied to update DDoS custom policy resource tags.
   276  func (client DdosCustomPoliciesClient) UpdateTags(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, parameters TagsObject) (result DdosCustomPolicy, err error) {
   277  	if tracing.IsEnabled() {
   278  		ctx = tracing.StartSpan(ctx, fqdn+"/DdosCustomPoliciesClient.UpdateTags")
   279  		defer func() {
   280  			sc := -1
   281  			if result.Response.Response != nil {
   282  				sc = result.Response.Response.StatusCode
   283  			}
   284  			tracing.EndSpan(ctx, sc, err)
   285  		}()
   286  	}
   287  	req, err := client.UpdateTagsPreparer(ctx, resourceGroupName, ddosCustomPolicyName, parameters)
   288  	if err != nil {
   289  		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "UpdateTags", nil, "Failure preparing request")
   290  		return
   291  	}
   292  
   293  	resp, err := client.UpdateTagsSender(req)
   294  	if err != nil {
   295  		result.Response = autorest.Response{Response: resp}
   296  		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "UpdateTags", resp, "Failure sending request")
   297  		return
   298  	}
   299  
   300  	result, err = client.UpdateTagsResponder(resp)
   301  	if err != nil {
   302  		err = autorest.NewErrorWithError(err, "network.DdosCustomPoliciesClient", "UpdateTags", resp, "Failure responding to request")
   303  		return
   304  	}
   305  
   306  	return
   307  }
   308  
   309  // UpdateTagsPreparer prepares the UpdateTags request.
   310  func (client DdosCustomPoliciesClient) UpdateTagsPreparer(ctx context.Context, resourceGroupName string, ddosCustomPolicyName string, parameters TagsObject) (*http.Request, error) {
   311  	pathParameters := map[string]interface{}{
   312  		"ddosCustomPolicyName": autorest.Encode("path", ddosCustomPolicyName),
   313  		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
   314  		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
   315  	}
   316  
   317  	const APIVersion = "2021-05-01"
   318  	queryParameters := map[string]interface{}{
   319  		"api-version": APIVersion,
   320  	}
   321  
   322  	preparer := autorest.CreatePreparer(
   323  		autorest.AsContentType("application/json; charset=utf-8"),
   324  		autorest.AsPatch(),
   325  		autorest.WithBaseURL(client.BaseURI),
   326  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/ddosCustomPolicies/{ddosCustomPolicyName}", pathParameters),
   327  		autorest.WithJSON(parameters),
   328  		autorest.WithQueryParameters(queryParameters))
   329  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   330  }
   331  
   332  // UpdateTagsSender sends the UpdateTags request. The method will close the
   333  // http.Response Body if it receives an error.
   334  func (client DdosCustomPoliciesClient) UpdateTagsSender(req *http.Request) (*http.Response, error) {
   335  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   336  }
   337  
   338  // UpdateTagsResponder handles the response to the UpdateTags request. The method always
   339  // closes the http.Response Body.
   340  func (client DdosCustomPoliciesClient) UpdateTagsResponder(resp *http.Response) (result DdosCustomPolicy, err error) {
   341  	err = autorest.Respond(
   342  		resp,
   343  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   344  		autorest.ByUnmarshallingJSON(&result),
   345  		autorest.ByClosing())
   346  	result.Response = autorest.Response{Response: resp}
   347  	return
   348  }
   349  

View as plain text