...

Source file src/github.com/Azure/azure-sdk-for-go/services/subscription/mgmt/2020-09-01/subscription/alias.go

Documentation: github.com/Azure/azure-sdk-for-go/services/subscription/mgmt/2020-09-01/subscription

     1  package subscription
     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  // AliasClient is the the subscription client
    19  type AliasClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewAliasClient creates an instance of the AliasClient client.
    24  func NewAliasClient() AliasClient {
    25  	return NewAliasClientWithBaseURI(DefaultBaseURI)
    26  }
    27  
    28  // NewAliasClientWithBaseURI creates an instance of the AliasClient client using a custom endpoint.  Use this when
    29  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewAliasClientWithBaseURI(baseURI string) AliasClient {
    31  	return AliasClient{NewWithBaseURI(baseURI)}
    32  }
    33  
    34  // Create create Alias Subscription.
    35  // Parameters:
    36  // aliasName - alias Name
    37  func (client AliasClient) Create(ctx context.Context, aliasName string, body PutAliasRequest) (result AliasCreateFuture, err error) {
    38  	if tracing.IsEnabled() {
    39  		ctx = tracing.StartSpan(ctx, fqdn+"/AliasClient.Create")
    40  		defer func() {
    41  			sc := -1
    42  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    43  				sc = result.FutureAPI.Response().StatusCode
    44  			}
    45  			tracing.EndSpan(ctx, sc, err)
    46  		}()
    47  	}
    48  	if err := validation.Validate([]validation.Validation{
    49  		{TargetValue: body,
    50  			Constraints: []validation.Constraint{{Target: "body.Properties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
    51  		return result, validation.NewError("subscription.AliasClient", "Create", err.Error())
    52  	}
    53  
    54  	req, err := client.CreatePreparer(ctx, aliasName, body)
    55  	if err != nil {
    56  		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Create", nil, "Failure preparing request")
    57  		return
    58  	}
    59  
    60  	result, err = client.CreateSender(req)
    61  	if err != nil {
    62  		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Create", result.Response(), "Failure sending request")
    63  		return
    64  	}
    65  
    66  	return
    67  }
    68  
    69  // CreatePreparer prepares the Create request.
    70  func (client AliasClient) CreatePreparer(ctx context.Context, aliasName string, body PutAliasRequest) (*http.Request, error) {
    71  	pathParameters := map[string]interface{}{
    72  		"aliasName": autorest.Encode("path", aliasName),
    73  	}
    74  
    75  	const APIVersion = "2020-09-01"
    76  	queryParameters := map[string]interface{}{
    77  		"api-version": APIVersion,
    78  	}
    79  
    80  	preparer := autorest.CreatePreparer(
    81  		autorest.AsContentType("application/json; charset=utf-8"),
    82  		autorest.AsPut(),
    83  		autorest.WithBaseURL(client.BaseURI),
    84  		autorest.WithPathParameters("/providers/Microsoft.Subscription/aliases/{aliasName}", pathParameters),
    85  		autorest.WithJSON(body),
    86  		autorest.WithQueryParameters(queryParameters))
    87  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    88  }
    89  
    90  // CreateSender sends the Create request. The method will close the
    91  // http.Response Body if it receives an error.
    92  func (client AliasClient) CreateSender(req *http.Request) (future AliasCreateFuture, err error) {
    93  	var resp *http.Response
    94  	future.FutureAPI = &azure.Future{}
    95  	resp, err = client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    96  	if err != nil {
    97  		return
    98  	}
    99  	var azf azure.Future
   100  	azf, err = azure.NewFutureFromResponse(resp)
   101  	future.FutureAPI = &azf
   102  	future.Result = future.result
   103  	return
   104  }
   105  
   106  // CreateResponder handles the response to the Create request. The method always
   107  // closes the http.Response Body.
   108  func (client AliasClient) CreateResponder(resp *http.Response) (result PutAliasResponse, err error) {
   109  	err = autorest.Respond(
   110  		resp,
   111  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   112  		autorest.ByUnmarshallingJSON(&result),
   113  		autorest.ByClosing())
   114  	result.Response = autorest.Response{Response: resp}
   115  	return
   116  }
   117  
   118  // Delete delete Alias.
   119  // Parameters:
   120  // aliasName - alias Name
   121  func (client AliasClient) Delete(ctx context.Context, aliasName string) (result autorest.Response, err error) {
   122  	if tracing.IsEnabled() {
   123  		ctx = tracing.StartSpan(ctx, fqdn+"/AliasClient.Delete")
   124  		defer func() {
   125  			sc := -1
   126  			if result.Response != nil {
   127  				sc = result.Response.StatusCode
   128  			}
   129  			tracing.EndSpan(ctx, sc, err)
   130  		}()
   131  	}
   132  	req, err := client.DeletePreparer(ctx, aliasName)
   133  	if err != nil {
   134  		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Delete", nil, "Failure preparing request")
   135  		return
   136  	}
   137  
   138  	resp, err := client.DeleteSender(req)
   139  	if err != nil {
   140  		result.Response = resp
   141  		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Delete", resp, "Failure sending request")
   142  		return
   143  	}
   144  
   145  	result, err = client.DeleteResponder(resp)
   146  	if err != nil {
   147  		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Delete", resp, "Failure responding to request")
   148  		return
   149  	}
   150  
   151  	return
   152  }
   153  
   154  // DeletePreparer prepares the Delete request.
   155  func (client AliasClient) DeletePreparer(ctx context.Context, aliasName string) (*http.Request, error) {
   156  	pathParameters := map[string]interface{}{
   157  		"aliasName": autorest.Encode("path", aliasName),
   158  	}
   159  
   160  	const APIVersion = "2020-09-01"
   161  	queryParameters := map[string]interface{}{
   162  		"api-version": APIVersion,
   163  	}
   164  
   165  	preparer := autorest.CreatePreparer(
   166  		autorest.AsDelete(),
   167  		autorest.WithBaseURL(client.BaseURI),
   168  		autorest.WithPathParameters("/providers/Microsoft.Subscription/aliases/{aliasName}", pathParameters),
   169  		autorest.WithQueryParameters(queryParameters))
   170  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   171  }
   172  
   173  // DeleteSender sends the Delete request. The method will close the
   174  // http.Response Body if it receives an error.
   175  func (client AliasClient) DeleteSender(req *http.Request) (*http.Response, error) {
   176  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   177  }
   178  
   179  // DeleteResponder handles the response to the Delete request. The method always
   180  // closes the http.Response Body.
   181  func (client AliasClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   182  	err = autorest.Respond(
   183  		resp,
   184  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   185  		autorest.ByClosing())
   186  	result.Response = resp
   187  	return
   188  }
   189  
   190  // Get get Alias Subscription.
   191  // Parameters:
   192  // aliasName - alias Name
   193  func (client AliasClient) Get(ctx context.Context, aliasName string) (result PutAliasResponse, err error) {
   194  	if tracing.IsEnabled() {
   195  		ctx = tracing.StartSpan(ctx, fqdn+"/AliasClient.Get")
   196  		defer func() {
   197  			sc := -1
   198  			if result.Response.Response != nil {
   199  				sc = result.Response.Response.StatusCode
   200  			}
   201  			tracing.EndSpan(ctx, sc, err)
   202  		}()
   203  	}
   204  	req, err := client.GetPreparer(ctx, aliasName)
   205  	if err != nil {
   206  		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Get", nil, "Failure preparing request")
   207  		return
   208  	}
   209  
   210  	resp, err := client.GetSender(req)
   211  	if err != nil {
   212  		result.Response = autorest.Response{Response: resp}
   213  		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Get", resp, "Failure sending request")
   214  		return
   215  	}
   216  
   217  	result, err = client.GetResponder(resp)
   218  	if err != nil {
   219  		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Get", resp, "Failure responding to request")
   220  		return
   221  	}
   222  
   223  	return
   224  }
   225  
   226  // GetPreparer prepares the Get request.
   227  func (client AliasClient) GetPreparer(ctx context.Context, aliasName string) (*http.Request, error) {
   228  	pathParameters := map[string]interface{}{
   229  		"aliasName": autorest.Encode("path", aliasName),
   230  	}
   231  
   232  	const APIVersion = "2020-09-01"
   233  	queryParameters := map[string]interface{}{
   234  		"api-version": APIVersion,
   235  	}
   236  
   237  	preparer := autorest.CreatePreparer(
   238  		autorest.AsGet(),
   239  		autorest.WithBaseURL(client.BaseURI),
   240  		autorest.WithPathParameters("/providers/Microsoft.Subscription/aliases/{aliasName}", pathParameters),
   241  		autorest.WithQueryParameters(queryParameters))
   242  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   243  }
   244  
   245  // GetSender sends the Get request. The method will close the
   246  // http.Response Body if it receives an error.
   247  func (client AliasClient) GetSender(req *http.Request) (*http.Response, error) {
   248  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   249  }
   250  
   251  // GetResponder handles the response to the Get request. The method always
   252  // closes the http.Response Body.
   253  func (client AliasClient) GetResponder(resp *http.Response) (result PutAliasResponse, err error) {
   254  	err = autorest.Respond(
   255  		resp,
   256  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   257  		autorest.ByUnmarshallingJSON(&result),
   258  		autorest.ByClosing())
   259  	result.Response = autorest.Response{Response: resp}
   260  	return
   261  }
   262  
   263  // List get Alias Subscription.
   264  func (client AliasClient) List(ctx context.Context) (result PutAliasListResult, err error) {
   265  	if tracing.IsEnabled() {
   266  		ctx = tracing.StartSpan(ctx, fqdn+"/AliasClient.List")
   267  		defer func() {
   268  			sc := -1
   269  			if result.Response.Response != nil {
   270  				sc = result.Response.Response.StatusCode
   271  			}
   272  			tracing.EndSpan(ctx, sc, err)
   273  		}()
   274  	}
   275  	req, err := client.ListPreparer(ctx)
   276  	if err != nil {
   277  		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "List", nil, "Failure preparing request")
   278  		return
   279  	}
   280  
   281  	resp, err := client.ListSender(req)
   282  	if err != nil {
   283  		result.Response = autorest.Response{Response: resp}
   284  		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "List", resp, "Failure sending request")
   285  		return
   286  	}
   287  
   288  	result, err = client.ListResponder(resp)
   289  	if err != nil {
   290  		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "List", resp, "Failure responding to request")
   291  		return
   292  	}
   293  
   294  	return
   295  }
   296  
   297  // ListPreparer prepares the List request.
   298  func (client AliasClient) ListPreparer(ctx context.Context) (*http.Request, error) {
   299  	const APIVersion = "2020-09-01"
   300  	queryParameters := map[string]interface{}{
   301  		"api-version": APIVersion,
   302  	}
   303  
   304  	preparer := autorest.CreatePreparer(
   305  		autorest.AsGet(),
   306  		autorest.WithBaseURL(client.BaseURI),
   307  		autorest.WithPath("/providers/Microsoft.Subscription/aliases"),
   308  		autorest.WithQueryParameters(queryParameters))
   309  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   310  }
   311  
   312  // ListSender sends the List request. The method will close the
   313  // http.Response Body if it receives an error.
   314  func (client AliasClient) ListSender(req *http.Request) (*http.Response, error) {
   315  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   316  }
   317  
   318  // ListResponder handles the response to the List request. The method always
   319  // closes the http.Response Body.
   320  func (client AliasClient) ListResponder(resp *http.Response) (result PutAliasListResult, err error) {
   321  	err = autorest.Respond(
   322  		resp,
   323  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   324  		autorest.ByUnmarshallingJSON(&result),
   325  		autorest.ByClosing())
   326  	result.Response = autorest.Response{Response: resp}
   327  	return
   328  }
   329  

View as plain text