...

Source file src/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2022-01-01/network/configurationpolicygroups.go

Documentation: github.com/Azure/azure-sdk-for-go/services/network/mgmt/2022-01-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  // ConfigurationPolicyGroupsClient is the network Client
    18  type ConfigurationPolicyGroupsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewConfigurationPolicyGroupsClient creates an instance of the ConfigurationPolicyGroupsClient client.
    23  func NewConfigurationPolicyGroupsClient(subscriptionID string) ConfigurationPolicyGroupsClient {
    24  	return NewConfigurationPolicyGroupsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewConfigurationPolicyGroupsClientWithBaseURI creates an instance of the ConfigurationPolicyGroupsClient 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).
    30  func NewConfigurationPolicyGroupsClientWithBaseURI(baseURI string, subscriptionID string) ConfigurationPolicyGroupsClient {
    31  	return ConfigurationPolicyGroupsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate creates a ConfigurationPolicyGroup if it doesn't exist else updates the existing one.
    35  // Parameters:
    36  // resourceGroupName - the resource group name of the ConfigurationPolicyGroup.
    37  // vpnServerConfigurationName - the name of the VpnServerConfiguration.
    38  // configurationPolicyGroupName - the name of the ConfigurationPolicyGroup.
    39  // vpnServerConfigurationPolicyGroupParameters - parameters supplied to create or update a
    40  // VpnServerConfiguration PolicyGroup.
    41  func (client ConfigurationPolicyGroupsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, configurationPolicyGroupName string, vpnServerConfigurationPolicyGroupParameters VpnServerConfigurationPolicyGroup) (result ConfigurationPolicyGroupsCreateOrUpdateFuture, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationPolicyGroupsClient.CreateOrUpdate")
    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  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, vpnServerConfigurationName, configurationPolicyGroupName, vpnServerConfigurationPolicyGroupParameters)
    53  	if err != nil {
    54  		err = autorest.NewErrorWithError(err, "network.ConfigurationPolicyGroupsClient", "CreateOrUpdate", nil, "Failure preparing request")
    55  		return
    56  	}
    57  
    58  	result, err = client.CreateOrUpdateSender(req)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "network.ConfigurationPolicyGroupsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    61  		return
    62  	}
    63  
    64  	return
    65  }
    66  
    67  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    68  func (client ConfigurationPolicyGroupsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, configurationPolicyGroupName string, vpnServerConfigurationPolicyGroupParameters VpnServerConfigurationPolicyGroup) (*http.Request, error) {
    69  	pathParameters := map[string]interface{}{
    70  		"configurationPolicyGroupName": autorest.Encode("path", configurationPolicyGroupName),
    71  		"resourceGroupName":            autorest.Encode("path", resourceGroupName),
    72  		"subscriptionId":               autorest.Encode("path", client.SubscriptionID),
    73  		"vpnServerConfigurationName":   autorest.Encode("path", vpnServerConfigurationName),
    74  	}
    75  
    76  	const APIVersion = "2022-01-01"
    77  	queryParameters := map[string]interface{}{
    78  		"api-version": APIVersion,
    79  	}
    80  
    81  	vpnServerConfigurationPolicyGroupParameters.Etag = nil
    82  	vpnServerConfigurationPolicyGroupParameters.Type = nil
    83  	preparer := autorest.CreatePreparer(
    84  		autorest.AsContentType("application/json; charset=utf-8"),
    85  		autorest.AsPut(),
    86  		autorest.WithBaseURL(client.BaseURI),
    87  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnServerConfigurations/{vpnServerConfigurationName}/configurationPolicyGroups/{configurationPolicyGroupName}", pathParameters),
    88  		autorest.WithJSON(vpnServerConfigurationPolicyGroupParameters),
    89  		autorest.WithQueryParameters(queryParameters))
    90  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    91  }
    92  
    93  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
    94  // http.Response Body if it receives an error.
    95  func (client ConfigurationPolicyGroupsClient) CreateOrUpdateSender(req *http.Request) (future ConfigurationPolicyGroupsCreateOrUpdateFuture, err error) {
    96  	var resp *http.Response
    97  	future.FutureAPI = &azure.Future{}
    98  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
    99  	if err != nil {
   100  		return
   101  	}
   102  	var azf azure.Future
   103  	azf, err = azure.NewFutureFromResponse(resp)
   104  	future.FutureAPI = &azf
   105  	future.Result = future.result
   106  	return
   107  }
   108  
   109  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   110  // closes the http.Response Body.
   111  func (client ConfigurationPolicyGroupsClient) CreateOrUpdateResponder(resp *http.Response) (result VpnServerConfigurationPolicyGroup, err error) {
   112  	err = autorest.Respond(
   113  		resp,
   114  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   115  		autorest.ByUnmarshallingJSON(&result),
   116  		autorest.ByClosing())
   117  	result.Response = autorest.Response{Response: resp}
   118  	return
   119  }
   120  
   121  // Delete deletes a ConfigurationPolicyGroup.
   122  // Parameters:
   123  // resourceGroupName - the resource group name of the ConfigurationPolicyGroup.
   124  // vpnServerConfigurationName - the name of the VpnServerConfiguration.
   125  // configurationPolicyGroupName - the name of the ConfigurationPolicyGroup.
   126  func (client ConfigurationPolicyGroupsClient) Delete(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, configurationPolicyGroupName string) (result ConfigurationPolicyGroupsDeleteFuture, err error) {
   127  	if tracing.IsEnabled() {
   128  		ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationPolicyGroupsClient.Delete")
   129  		defer func() {
   130  			sc := -1
   131  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   132  				sc = result.FutureAPI.Response().StatusCode
   133  			}
   134  			tracing.EndSpan(ctx, sc, err)
   135  		}()
   136  	}
   137  	req, err := client.DeletePreparer(ctx, resourceGroupName, vpnServerConfigurationName, configurationPolicyGroupName)
   138  	if err != nil {
   139  		err = autorest.NewErrorWithError(err, "network.ConfigurationPolicyGroupsClient", "Delete", nil, "Failure preparing request")
   140  		return
   141  	}
   142  
   143  	result, err = client.DeleteSender(req)
   144  	if err != nil {
   145  		err = autorest.NewErrorWithError(err, "network.ConfigurationPolicyGroupsClient", "Delete", result.Response(), "Failure sending request")
   146  		return
   147  	}
   148  
   149  	return
   150  }
   151  
   152  // DeletePreparer prepares the Delete request.
   153  func (client ConfigurationPolicyGroupsClient) DeletePreparer(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, configurationPolicyGroupName string) (*http.Request, error) {
   154  	pathParameters := map[string]interface{}{
   155  		"configurationPolicyGroupName": autorest.Encode("path", configurationPolicyGroupName),
   156  		"resourceGroupName":            autorest.Encode("path", resourceGroupName),
   157  		"subscriptionId":               autorest.Encode("path", client.SubscriptionID),
   158  		"vpnServerConfigurationName":   autorest.Encode("path", vpnServerConfigurationName),
   159  	}
   160  
   161  	const APIVersion = "2022-01-01"
   162  	queryParameters := map[string]interface{}{
   163  		"api-version": APIVersion,
   164  	}
   165  
   166  	preparer := autorest.CreatePreparer(
   167  		autorest.AsDelete(),
   168  		autorest.WithBaseURL(client.BaseURI),
   169  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnServerConfigurations/{vpnServerConfigurationName}/configurationPolicyGroups/{configurationPolicyGroupName}", pathParameters),
   170  		autorest.WithQueryParameters(queryParameters))
   171  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   172  }
   173  
   174  // DeleteSender sends the Delete request. The method will close the
   175  // http.Response Body if it receives an error.
   176  func (client ConfigurationPolicyGroupsClient) DeleteSender(req *http.Request) (future ConfigurationPolicyGroupsDeleteFuture, err error) {
   177  	var resp *http.Response
   178  	future.FutureAPI = &azure.Future{}
   179  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   180  	if err != nil {
   181  		return
   182  	}
   183  	var azf azure.Future
   184  	azf, err = azure.NewFutureFromResponse(resp)
   185  	future.FutureAPI = &azf
   186  	future.Result = future.result
   187  	return
   188  }
   189  
   190  // DeleteResponder handles the response to the Delete request. The method always
   191  // closes the http.Response Body.
   192  func (client ConfigurationPolicyGroupsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   193  	err = autorest.Respond(
   194  		resp,
   195  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   196  		autorest.ByClosing())
   197  	result.Response = resp
   198  	return
   199  }
   200  
   201  // Get retrieves the details of a ConfigurationPolicyGroup.
   202  // Parameters:
   203  // resourceGroupName - the resource group name of the VpnServerConfiguration.
   204  // vpnServerConfigurationName - the name of the VpnServerConfiguration.
   205  // configurationPolicyGroupName - the name of the ConfigurationPolicyGroup being retrieved.
   206  func (client ConfigurationPolicyGroupsClient) Get(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, configurationPolicyGroupName string) (result VpnServerConfigurationPolicyGroup, err error) {
   207  	if tracing.IsEnabled() {
   208  		ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationPolicyGroupsClient.Get")
   209  		defer func() {
   210  			sc := -1
   211  			if result.Response.Response != nil {
   212  				sc = result.Response.Response.StatusCode
   213  			}
   214  			tracing.EndSpan(ctx, sc, err)
   215  		}()
   216  	}
   217  	req, err := client.GetPreparer(ctx, resourceGroupName, vpnServerConfigurationName, configurationPolicyGroupName)
   218  	if err != nil {
   219  		err = autorest.NewErrorWithError(err, "network.ConfigurationPolicyGroupsClient", "Get", nil, "Failure preparing request")
   220  		return
   221  	}
   222  
   223  	resp, err := client.GetSender(req)
   224  	if err != nil {
   225  		result.Response = autorest.Response{Response: resp}
   226  		err = autorest.NewErrorWithError(err, "network.ConfigurationPolicyGroupsClient", "Get", resp, "Failure sending request")
   227  		return
   228  	}
   229  
   230  	result, err = client.GetResponder(resp)
   231  	if err != nil {
   232  		err = autorest.NewErrorWithError(err, "network.ConfigurationPolicyGroupsClient", "Get", resp, "Failure responding to request")
   233  		return
   234  	}
   235  
   236  	return
   237  }
   238  
   239  // GetPreparer prepares the Get request.
   240  func (client ConfigurationPolicyGroupsClient) GetPreparer(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, configurationPolicyGroupName string) (*http.Request, error) {
   241  	pathParameters := map[string]interface{}{
   242  		"configurationPolicyGroupName": autorest.Encode("path", configurationPolicyGroupName),
   243  		"resourceGroupName":            autorest.Encode("path", resourceGroupName),
   244  		"subscriptionId":               autorest.Encode("path", client.SubscriptionID),
   245  		"vpnServerConfigurationName":   autorest.Encode("path", vpnServerConfigurationName),
   246  	}
   247  
   248  	const APIVersion = "2022-01-01"
   249  	queryParameters := map[string]interface{}{
   250  		"api-version": APIVersion,
   251  	}
   252  
   253  	preparer := autorest.CreatePreparer(
   254  		autorest.AsGet(),
   255  		autorest.WithBaseURL(client.BaseURI),
   256  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnServerConfigurations/{vpnServerConfigurationName}/configurationPolicyGroups/{configurationPolicyGroupName}", pathParameters),
   257  		autorest.WithQueryParameters(queryParameters))
   258  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   259  }
   260  
   261  // GetSender sends the Get request. The method will close the
   262  // http.Response Body if it receives an error.
   263  func (client ConfigurationPolicyGroupsClient) GetSender(req *http.Request) (*http.Response, error) {
   264  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   265  }
   266  
   267  // GetResponder handles the response to the Get request. The method always
   268  // closes the http.Response Body.
   269  func (client ConfigurationPolicyGroupsClient) GetResponder(resp *http.Response) (result VpnServerConfigurationPolicyGroup, err error) {
   270  	err = autorest.Respond(
   271  		resp,
   272  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   273  		autorest.ByUnmarshallingJSON(&result),
   274  		autorest.ByClosing())
   275  	result.Response = autorest.Response{Response: resp}
   276  	return
   277  }
   278  
   279  // ListByVpnServerConfiguration lists all the configurationPolicyGroups in a resource group for a
   280  // vpnServerConfiguration.
   281  // Parameters:
   282  // resourceGroupName - the resource group name of the VpnServerConfiguration.
   283  // vpnServerConfigurationName - the name of the VpnServerConfiguration.
   284  func (client ConfigurationPolicyGroupsClient) ListByVpnServerConfiguration(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string) (result ListVpnServerConfigurationPolicyGroupsResultPage, err error) {
   285  	if tracing.IsEnabled() {
   286  		ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationPolicyGroupsClient.ListByVpnServerConfiguration")
   287  		defer func() {
   288  			sc := -1
   289  			if result.lvscpgr.Response.Response != nil {
   290  				sc = result.lvscpgr.Response.Response.StatusCode
   291  			}
   292  			tracing.EndSpan(ctx, sc, err)
   293  		}()
   294  	}
   295  	result.fn = client.listByVpnServerConfigurationNextResults
   296  	req, err := client.ListByVpnServerConfigurationPreparer(ctx, resourceGroupName, vpnServerConfigurationName)
   297  	if err != nil {
   298  		err = autorest.NewErrorWithError(err, "network.ConfigurationPolicyGroupsClient", "ListByVpnServerConfiguration", nil, "Failure preparing request")
   299  		return
   300  	}
   301  
   302  	resp, err := client.ListByVpnServerConfigurationSender(req)
   303  	if err != nil {
   304  		result.lvscpgr.Response = autorest.Response{Response: resp}
   305  		err = autorest.NewErrorWithError(err, "network.ConfigurationPolicyGroupsClient", "ListByVpnServerConfiguration", resp, "Failure sending request")
   306  		return
   307  	}
   308  
   309  	result.lvscpgr, err = client.ListByVpnServerConfigurationResponder(resp)
   310  	if err != nil {
   311  		err = autorest.NewErrorWithError(err, "network.ConfigurationPolicyGroupsClient", "ListByVpnServerConfiguration", resp, "Failure responding to request")
   312  		return
   313  	}
   314  	if result.lvscpgr.hasNextLink() && result.lvscpgr.IsEmpty() {
   315  		err = result.NextWithContext(ctx)
   316  		return
   317  	}
   318  
   319  	return
   320  }
   321  
   322  // ListByVpnServerConfigurationPreparer prepares the ListByVpnServerConfiguration request.
   323  func (client ConfigurationPolicyGroupsClient) ListByVpnServerConfigurationPreparer(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string) (*http.Request, error) {
   324  	pathParameters := map[string]interface{}{
   325  		"resourceGroupName":          autorest.Encode("path", resourceGroupName),
   326  		"subscriptionId":             autorest.Encode("path", client.SubscriptionID),
   327  		"vpnServerConfigurationName": autorest.Encode("path", vpnServerConfigurationName),
   328  	}
   329  
   330  	const APIVersion = "2022-01-01"
   331  	queryParameters := map[string]interface{}{
   332  		"api-version": APIVersion,
   333  	}
   334  
   335  	preparer := autorest.CreatePreparer(
   336  		autorest.AsGet(),
   337  		autorest.WithBaseURL(client.BaseURI),
   338  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnServerConfigurations/{vpnServerConfigurationName}/configurationPolicyGroups", pathParameters),
   339  		autorest.WithQueryParameters(queryParameters))
   340  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   341  }
   342  
   343  // ListByVpnServerConfigurationSender sends the ListByVpnServerConfiguration request. The method will close the
   344  // http.Response Body if it receives an error.
   345  func (client ConfigurationPolicyGroupsClient) ListByVpnServerConfigurationSender(req *http.Request) (*http.Response, error) {
   346  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   347  }
   348  
   349  // ListByVpnServerConfigurationResponder handles the response to the ListByVpnServerConfiguration request. The method always
   350  // closes the http.Response Body.
   351  func (client ConfigurationPolicyGroupsClient) ListByVpnServerConfigurationResponder(resp *http.Response) (result ListVpnServerConfigurationPolicyGroupsResult, err error) {
   352  	err = autorest.Respond(
   353  		resp,
   354  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   355  		autorest.ByUnmarshallingJSON(&result),
   356  		autorest.ByClosing())
   357  	result.Response = autorest.Response{Response: resp}
   358  	return
   359  }
   360  
   361  // listByVpnServerConfigurationNextResults retrieves the next set of results, if any.
   362  func (client ConfigurationPolicyGroupsClient) listByVpnServerConfigurationNextResults(ctx context.Context, lastResults ListVpnServerConfigurationPolicyGroupsResult) (result ListVpnServerConfigurationPolicyGroupsResult, err error) {
   363  	req, err := lastResults.listVpnServerConfigurationPolicyGroupsResultPreparer(ctx)
   364  	if err != nil {
   365  		return result, autorest.NewErrorWithError(err, "network.ConfigurationPolicyGroupsClient", "listByVpnServerConfigurationNextResults", nil, "Failure preparing next results request")
   366  	}
   367  	if req == nil {
   368  		return
   369  	}
   370  	resp, err := client.ListByVpnServerConfigurationSender(req)
   371  	if err != nil {
   372  		result.Response = autorest.Response{Response: resp}
   373  		return result, autorest.NewErrorWithError(err, "network.ConfigurationPolicyGroupsClient", "listByVpnServerConfigurationNextResults", resp, "Failure sending next results request")
   374  	}
   375  	result, err = client.ListByVpnServerConfigurationResponder(resp)
   376  	if err != nil {
   377  		err = autorest.NewErrorWithError(err, "network.ConfigurationPolicyGroupsClient", "listByVpnServerConfigurationNextResults", resp, "Failure responding to next results request")
   378  	}
   379  	return
   380  }
   381  
   382  // ListByVpnServerConfigurationComplete enumerates all values, automatically crossing page boundaries as required.
   383  func (client ConfigurationPolicyGroupsClient) ListByVpnServerConfigurationComplete(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string) (result ListVpnServerConfigurationPolicyGroupsResultIterator, err error) {
   384  	if tracing.IsEnabled() {
   385  		ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationPolicyGroupsClient.ListByVpnServerConfiguration")
   386  		defer func() {
   387  			sc := -1
   388  			if result.Response().Response.Response != nil {
   389  				sc = result.page.Response().Response.Response.StatusCode
   390  			}
   391  			tracing.EndSpan(ctx, sc, err)
   392  		}()
   393  	}
   394  	result.page, err = client.ListByVpnServerConfiguration(ctx, resourceGroupName, vpnServerConfigurationName)
   395  	return
   396  }
   397  

View as plain text