...

Source file src/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2021-07-01/features/features.go

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2021-07-01/features

     1  package features
     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  // Client is the client for the Features methods of the Features service.
    18  type Client struct {
    19  	BaseClient
    20  }
    21  
    22  // NewClient creates an instance of the Client client.
    23  func NewClient(subscriptionID string) Client {
    24  	return NewClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewClientWithBaseURI creates an instance of the Client client using a custom endpoint.  Use this when interacting
    28  // with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewClientWithBaseURI(baseURI string, subscriptionID string) Client {
    30  	return Client{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // Get gets the preview feature with the specified name.
    34  // Parameters:
    35  // resourceProviderNamespace - the resource provider namespace for the feature.
    36  // featureName - the name of the feature to get.
    37  func (client Client) Get(ctx context.Context, resourceProviderNamespace string, featureName string) (result Result, err error) {
    38  	if tracing.IsEnabled() {
    39  		ctx = tracing.StartSpan(ctx, fqdn+"/Client.Get")
    40  		defer func() {
    41  			sc := -1
    42  			if result.Response.Response != nil {
    43  				sc = result.Response.Response.StatusCode
    44  			}
    45  			tracing.EndSpan(ctx, sc, err)
    46  		}()
    47  	}
    48  	req, err := client.GetPreparer(ctx, resourceProviderNamespace, featureName)
    49  	if err != nil {
    50  		err = autorest.NewErrorWithError(err, "features.Client", "Get", nil, "Failure preparing request")
    51  		return
    52  	}
    53  
    54  	resp, err := client.GetSender(req)
    55  	if err != nil {
    56  		result.Response = autorest.Response{Response: resp}
    57  		err = autorest.NewErrorWithError(err, "features.Client", "Get", resp, "Failure sending request")
    58  		return
    59  	}
    60  
    61  	result, err = client.GetResponder(resp)
    62  	if err != nil {
    63  		err = autorest.NewErrorWithError(err, "features.Client", "Get", resp, "Failure responding to request")
    64  		return
    65  	}
    66  
    67  	return
    68  }
    69  
    70  // GetPreparer prepares the Get request.
    71  func (client Client) GetPreparer(ctx context.Context, resourceProviderNamespace string, featureName string) (*http.Request, error) {
    72  	pathParameters := map[string]interface{}{
    73  		"featureName":               autorest.Encode("path", featureName),
    74  		"resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace),
    75  		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
    76  	}
    77  
    78  	const APIVersion = "2021-07-01"
    79  	queryParameters := map[string]interface{}{
    80  		"api-version": APIVersion,
    81  	}
    82  
    83  	preparer := autorest.CreatePreparer(
    84  		autorest.AsGet(),
    85  		autorest.WithBaseURL(client.BaseURI),
    86  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Features/providers/{resourceProviderNamespace}/features/{featureName}", pathParameters),
    87  		autorest.WithQueryParameters(queryParameters))
    88  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    89  }
    90  
    91  // GetSender sends the Get request. The method will close the
    92  // http.Response Body if it receives an error.
    93  func (client Client) GetSender(req *http.Request) (*http.Response, error) {
    94  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
    95  }
    96  
    97  // GetResponder handles the response to the Get request. The method always
    98  // closes the http.Response Body.
    99  func (client Client) GetResponder(resp *http.Response) (result Result, err error) {
   100  	err = autorest.Respond(
   101  		resp,
   102  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   103  		autorest.ByUnmarshallingJSON(&result),
   104  		autorest.ByClosing())
   105  	result.Response = autorest.Response{Response: resp}
   106  	return
   107  }
   108  
   109  // List gets all the preview features in a provider namespace that are available through AFEC for the subscription.
   110  // Parameters:
   111  // resourceProviderNamespace - the namespace of the resource provider for getting features.
   112  func (client Client) List(ctx context.Context, resourceProviderNamespace string) (result OperationsListResultPage, err error) {
   113  	if tracing.IsEnabled() {
   114  		ctx = tracing.StartSpan(ctx, fqdn+"/Client.List")
   115  		defer func() {
   116  			sc := -1
   117  			if result.olr.Response.Response != nil {
   118  				sc = result.olr.Response.Response.StatusCode
   119  			}
   120  			tracing.EndSpan(ctx, sc, err)
   121  		}()
   122  	}
   123  	result.fn = client.listNextResults
   124  	req, err := client.ListPreparer(ctx, resourceProviderNamespace)
   125  	if err != nil {
   126  		err = autorest.NewErrorWithError(err, "features.Client", "List", nil, "Failure preparing request")
   127  		return
   128  	}
   129  
   130  	resp, err := client.ListSender(req)
   131  	if err != nil {
   132  		result.olr.Response = autorest.Response{Response: resp}
   133  		err = autorest.NewErrorWithError(err, "features.Client", "List", resp, "Failure sending request")
   134  		return
   135  	}
   136  
   137  	result.olr, err = client.ListResponder(resp)
   138  	if err != nil {
   139  		err = autorest.NewErrorWithError(err, "features.Client", "List", resp, "Failure responding to request")
   140  		return
   141  	}
   142  	if result.olr.hasNextLink() && result.olr.IsEmpty() {
   143  		err = result.NextWithContext(ctx)
   144  		return
   145  	}
   146  
   147  	return
   148  }
   149  
   150  // ListPreparer prepares the List request.
   151  func (client Client) ListPreparer(ctx context.Context, resourceProviderNamespace string) (*http.Request, error) {
   152  	pathParameters := map[string]interface{}{
   153  		"resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace),
   154  		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
   155  	}
   156  
   157  	const APIVersion = "2021-07-01"
   158  	queryParameters := map[string]interface{}{
   159  		"api-version": APIVersion,
   160  	}
   161  
   162  	preparer := autorest.CreatePreparer(
   163  		autorest.AsGet(),
   164  		autorest.WithBaseURL(client.BaseURI),
   165  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Features/providers/{resourceProviderNamespace}/features", pathParameters),
   166  		autorest.WithQueryParameters(queryParameters))
   167  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   168  }
   169  
   170  // ListSender sends the List request. The method will close the
   171  // http.Response Body if it receives an error.
   172  func (client Client) ListSender(req *http.Request) (*http.Response, error) {
   173  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   174  }
   175  
   176  // ListResponder handles the response to the List request. The method always
   177  // closes the http.Response Body.
   178  func (client Client) ListResponder(resp *http.Response) (result OperationsListResult, err error) {
   179  	err = autorest.Respond(
   180  		resp,
   181  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   182  		autorest.ByUnmarshallingJSON(&result),
   183  		autorest.ByClosing())
   184  	result.Response = autorest.Response{Response: resp}
   185  	return
   186  }
   187  
   188  // listNextResults retrieves the next set of results, if any.
   189  func (client Client) listNextResults(ctx context.Context, lastResults OperationsListResult) (result OperationsListResult, err error) {
   190  	req, err := lastResults.operationsListResultPreparer(ctx)
   191  	if err != nil {
   192  		return result, autorest.NewErrorWithError(err, "features.Client", "listNextResults", nil, "Failure preparing next results request")
   193  	}
   194  	if req == nil {
   195  		return
   196  	}
   197  	resp, err := client.ListSender(req)
   198  	if err != nil {
   199  		result.Response = autorest.Response{Response: resp}
   200  		return result, autorest.NewErrorWithError(err, "features.Client", "listNextResults", resp, "Failure sending next results request")
   201  	}
   202  	result, err = client.ListResponder(resp)
   203  	if err != nil {
   204  		err = autorest.NewErrorWithError(err, "features.Client", "listNextResults", resp, "Failure responding to next results request")
   205  	}
   206  	return
   207  }
   208  
   209  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   210  func (client Client) ListComplete(ctx context.Context, resourceProviderNamespace string) (result OperationsListResultIterator, err error) {
   211  	if tracing.IsEnabled() {
   212  		ctx = tracing.StartSpan(ctx, fqdn+"/Client.List")
   213  		defer func() {
   214  			sc := -1
   215  			if result.Response().Response.Response != nil {
   216  				sc = result.page.Response().Response.Response.StatusCode
   217  			}
   218  			tracing.EndSpan(ctx, sc, err)
   219  		}()
   220  	}
   221  	result.page, err = client.List(ctx, resourceProviderNamespace)
   222  	return
   223  }
   224  
   225  // ListAll gets all the preview features that are available through AFEC for the subscription.
   226  func (client Client) ListAll(ctx context.Context) (result OperationsListResultPage, err error) {
   227  	if tracing.IsEnabled() {
   228  		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListAll")
   229  		defer func() {
   230  			sc := -1
   231  			if result.olr.Response.Response != nil {
   232  				sc = result.olr.Response.Response.StatusCode
   233  			}
   234  			tracing.EndSpan(ctx, sc, err)
   235  		}()
   236  	}
   237  	result.fn = client.listAllNextResults
   238  	req, err := client.ListAllPreparer(ctx)
   239  	if err != nil {
   240  		err = autorest.NewErrorWithError(err, "features.Client", "ListAll", nil, "Failure preparing request")
   241  		return
   242  	}
   243  
   244  	resp, err := client.ListAllSender(req)
   245  	if err != nil {
   246  		result.olr.Response = autorest.Response{Response: resp}
   247  		err = autorest.NewErrorWithError(err, "features.Client", "ListAll", resp, "Failure sending request")
   248  		return
   249  	}
   250  
   251  	result.olr, err = client.ListAllResponder(resp)
   252  	if err != nil {
   253  		err = autorest.NewErrorWithError(err, "features.Client", "ListAll", resp, "Failure responding to request")
   254  		return
   255  	}
   256  	if result.olr.hasNextLink() && result.olr.IsEmpty() {
   257  		err = result.NextWithContext(ctx)
   258  		return
   259  	}
   260  
   261  	return
   262  }
   263  
   264  // ListAllPreparer prepares the ListAll request.
   265  func (client Client) ListAllPreparer(ctx context.Context) (*http.Request, error) {
   266  	pathParameters := map[string]interface{}{
   267  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   268  	}
   269  
   270  	const APIVersion = "2021-07-01"
   271  	queryParameters := map[string]interface{}{
   272  		"api-version": APIVersion,
   273  	}
   274  
   275  	preparer := autorest.CreatePreparer(
   276  		autorest.AsGet(),
   277  		autorest.WithBaseURL(client.BaseURI),
   278  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Features/features", pathParameters),
   279  		autorest.WithQueryParameters(queryParameters))
   280  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   281  }
   282  
   283  // ListAllSender sends the ListAll request. The method will close the
   284  // http.Response Body if it receives an error.
   285  func (client Client) ListAllSender(req *http.Request) (*http.Response, error) {
   286  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   287  }
   288  
   289  // ListAllResponder handles the response to the ListAll request. The method always
   290  // closes the http.Response Body.
   291  func (client Client) ListAllResponder(resp *http.Response) (result OperationsListResult, err error) {
   292  	err = autorest.Respond(
   293  		resp,
   294  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   295  		autorest.ByUnmarshallingJSON(&result),
   296  		autorest.ByClosing())
   297  	result.Response = autorest.Response{Response: resp}
   298  	return
   299  }
   300  
   301  // listAllNextResults retrieves the next set of results, if any.
   302  func (client Client) listAllNextResults(ctx context.Context, lastResults OperationsListResult) (result OperationsListResult, err error) {
   303  	req, err := lastResults.operationsListResultPreparer(ctx)
   304  	if err != nil {
   305  		return result, autorest.NewErrorWithError(err, "features.Client", "listAllNextResults", nil, "Failure preparing next results request")
   306  	}
   307  	if req == nil {
   308  		return
   309  	}
   310  	resp, err := client.ListAllSender(req)
   311  	if err != nil {
   312  		result.Response = autorest.Response{Response: resp}
   313  		return result, autorest.NewErrorWithError(err, "features.Client", "listAllNextResults", resp, "Failure sending next results request")
   314  	}
   315  	result, err = client.ListAllResponder(resp)
   316  	if err != nil {
   317  		err = autorest.NewErrorWithError(err, "features.Client", "listAllNextResults", resp, "Failure responding to next results request")
   318  	}
   319  	return
   320  }
   321  
   322  // ListAllComplete enumerates all values, automatically crossing page boundaries as required.
   323  func (client Client) ListAllComplete(ctx context.Context) (result OperationsListResultIterator, err error) {
   324  	if tracing.IsEnabled() {
   325  		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListAll")
   326  		defer func() {
   327  			sc := -1
   328  			if result.Response().Response.Response != nil {
   329  				sc = result.page.Response().Response.Response.StatusCode
   330  			}
   331  			tracing.EndSpan(ctx, sc, err)
   332  		}()
   333  	}
   334  	result.page, err = client.ListAll(ctx)
   335  	return
   336  }
   337  
   338  // Register registers the preview feature for the subscription.
   339  // Parameters:
   340  // resourceProviderNamespace - the namespace of the resource provider.
   341  // featureName - the name of the feature to register.
   342  func (client Client) Register(ctx context.Context, resourceProviderNamespace string, featureName string) (result Result, err error) {
   343  	if tracing.IsEnabled() {
   344  		ctx = tracing.StartSpan(ctx, fqdn+"/Client.Register")
   345  		defer func() {
   346  			sc := -1
   347  			if result.Response.Response != nil {
   348  				sc = result.Response.Response.StatusCode
   349  			}
   350  			tracing.EndSpan(ctx, sc, err)
   351  		}()
   352  	}
   353  	req, err := client.RegisterPreparer(ctx, resourceProviderNamespace, featureName)
   354  	if err != nil {
   355  		err = autorest.NewErrorWithError(err, "features.Client", "Register", nil, "Failure preparing request")
   356  		return
   357  	}
   358  
   359  	resp, err := client.RegisterSender(req)
   360  	if err != nil {
   361  		result.Response = autorest.Response{Response: resp}
   362  		err = autorest.NewErrorWithError(err, "features.Client", "Register", resp, "Failure sending request")
   363  		return
   364  	}
   365  
   366  	result, err = client.RegisterResponder(resp)
   367  	if err != nil {
   368  		err = autorest.NewErrorWithError(err, "features.Client", "Register", resp, "Failure responding to request")
   369  		return
   370  	}
   371  
   372  	return
   373  }
   374  
   375  // RegisterPreparer prepares the Register request.
   376  func (client Client) RegisterPreparer(ctx context.Context, resourceProviderNamespace string, featureName string) (*http.Request, error) {
   377  	pathParameters := map[string]interface{}{
   378  		"featureName":               autorest.Encode("path", featureName),
   379  		"resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace),
   380  		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
   381  	}
   382  
   383  	const APIVersion = "2021-07-01"
   384  	queryParameters := map[string]interface{}{
   385  		"api-version": APIVersion,
   386  	}
   387  
   388  	preparer := autorest.CreatePreparer(
   389  		autorest.AsPost(),
   390  		autorest.WithBaseURL(client.BaseURI),
   391  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Features/providers/{resourceProviderNamespace}/features/{featureName}/register", pathParameters),
   392  		autorest.WithQueryParameters(queryParameters))
   393  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   394  }
   395  
   396  // RegisterSender sends the Register request. The method will close the
   397  // http.Response Body if it receives an error.
   398  func (client Client) RegisterSender(req *http.Request) (*http.Response, error) {
   399  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   400  }
   401  
   402  // RegisterResponder handles the response to the Register request. The method always
   403  // closes the http.Response Body.
   404  func (client Client) RegisterResponder(resp *http.Response) (result Result, err error) {
   405  	err = autorest.Respond(
   406  		resp,
   407  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   408  		autorest.ByUnmarshallingJSON(&result),
   409  		autorest.ByClosing())
   410  	result.Response = autorest.Response{Response: resp}
   411  	return
   412  }
   413  
   414  // Unregister unregisters the preview feature for the subscription.
   415  // Parameters:
   416  // resourceProviderNamespace - the namespace of the resource provider.
   417  // featureName - the name of the feature to unregister.
   418  func (client Client) Unregister(ctx context.Context, resourceProviderNamespace string, featureName string) (result Result, err error) {
   419  	if tracing.IsEnabled() {
   420  		ctx = tracing.StartSpan(ctx, fqdn+"/Client.Unregister")
   421  		defer func() {
   422  			sc := -1
   423  			if result.Response.Response != nil {
   424  				sc = result.Response.Response.StatusCode
   425  			}
   426  			tracing.EndSpan(ctx, sc, err)
   427  		}()
   428  	}
   429  	req, err := client.UnregisterPreparer(ctx, resourceProviderNamespace, featureName)
   430  	if err != nil {
   431  		err = autorest.NewErrorWithError(err, "features.Client", "Unregister", nil, "Failure preparing request")
   432  		return
   433  	}
   434  
   435  	resp, err := client.UnregisterSender(req)
   436  	if err != nil {
   437  		result.Response = autorest.Response{Response: resp}
   438  		err = autorest.NewErrorWithError(err, "features.Client", "Unregister", resp, "Failure sending request")
   439  		return
   440  	}
   441  
   442  	result, err = client.UnregisterResponder(resp)
   443  	if err != nil {
   444  		err = autorest.NewErrorWithError(err, "features.Client", "Unregister", resp, "Failure responding to request")
   445  		return
   446  	}
   447  
   448  	return
   449  }
   450  
   451  // UnregisterPreparer prepares the Unregister request.
   452  func (client Client) UnregisterPreparer(ctx context.Context, resourceProviderNamespace string, featureName string) (*http.Request, error) {
   453  	pathParameters := map[string]interface{}{
   454  		"featureName":               autorest.Encode("path", featureName),
   455  		"resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace),
   456  		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
   457  	}
   458  
   459  	const APIVersion = "2021-07-01"
   460  	queryParameters := map[string]interface{}{
   461  		"api-version": APIVersion,
   462  	}
   463  
   464  	preparer := autorest.CreatePreparer(
   465  		autorest.AsPost(),
   466  		autorest.WithBaseURL(client.BaseURI),
   467  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Features/providers/{resourceProviderNamespace}/features/{featureName}/unregister", pathParameters),
   468  		autorest.WithQueryParameters(queryParameters))
   469  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   470  }
   471  
   472  // UnregisterSender sends the Unregister request. The method will close the
   473  // http.Response Body if it receives an error.
   474  func (client Client) UnregisterSender(req *http.Request) (*http.Response, error) {
   475  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   476  }
   477  
   478  // UnregisterResponder handles the response to the Unregister request. The method always
   479  // closes the http.Response Body.
   480  func (client Client) UnregisterResponder(resp *http.Response) (result Result, err error) {
   481  	err = autorest.Respond(
   482  		resp,
   483  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   484  		autorest.ByUnmarshallingJSON(&result),
   485  		autorest.ByClosing())
   486  	result.Response = autorest.Response{Response: resp}
   487  	return
   488  }
   489  

View as plain text