...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/appinsights/mgmt/2022-02-01-preview/insights/componentlinkedstorageaccounts.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/appinsights/mgmt/2022-02-01-preview/insights

     1  package insights
     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  // ComponentLinkedStorageAccountsClient is the composite Swagger for Application Insights Management Client
    19  type ComponentLinkedStorageAccountsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewComponentLinkedStorageAccountsClient creates an instance of the ComponentLinkedStorageAccountsClient client.
    24  func NewComponentLinkedStorageAccountsClient(subscriptionID string) ComponentLinkedStorageAccountsClient {
    25  	return NewComponentLinkedStorageAccountsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewComponentLinkedStorageAccountsClientWithBaseURI creates an instance of the ComponentLinkedStorageAccountsClient
    29  // client using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI
    30  // (sovereign clouds, Azure stack).
    31  func NewComponentLinkedStorageAccountsClientWithBaseURI(baseURI string, subscriptionID string) ComponentLinkedStorageAccountsClient {
    32  	return ComponentLinkedStorageAccountsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // CreateAndUpdate replace current linked storage account for an Application Insights component.
    36  // Parameters:
    37  // resourceGroupName - the name of the resource group. The name is case insensitive.
    38  // resourceName - the name of the Application Insights component resource.
    39  // linkedStorageAccountsProperties - properties that need to be specified to update linked storage accounts for
    40  // an Application Insights component.
    41  func (client ComponentLinkedStorageAccountsClient) CreateAndUpdate(ctx context.Context, resourceGroupName string, resourceName string, linkedStorageAccountsProperties ComponentLinkedStorageAccounts) (result ComponentLinkedStorageAccounts, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/ComponentLinkedStorageAccountsClient.CreateAndUpdate")
    44  		defer func() {
    45  			sc := -1
    46  			if result.Response.Response != nil {
    47  				sc = result.Response.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  		{TargetValue: client.SubscriptionID,
    57  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
    58  		return result, validation.NewError("insights.ComponentLinkedStorageAccountsClient", "CreateAndUpdate", err.Error())
    59  	}
    60  
    61  	req, err := client.CreateAndUpdatePreparer(ctx, resourceGroupName, resourceName, linkedStorageAccountsProperties)
    62  	if err != nil {
    63  		err = autorest.NewErrorWithError(err, "insights.ComponentLinkedStorageAccountsClient", "CreateAndUpdate", nil, "Failure preparing request")
    64  		return
    65  	}
    66  
    67  	resp, err := client.CreateAndUpdateSender(req)
    68  	if err != nil {
    69  		result.Response = autorest.Response{Response: resp}
    70  		err = autorest.NewErrorWithError(err, "insights.ComponentLinkedStorageAccountsClient", "CreateAndUpdate", resp, "Failure sending request")
    71  		return
    72  	}
    73  
    74  	result, err = client.CreateAndUpdateResponder(resp)
    75  	if err != nil {
    76  		err = autorest.NewErrorWithError(err, "insights.ComponentLinkedStorageAccountsClient", "CreateAndUpdate", resp, "Failure responding to request")
    77  		return
    78  	}
    79  
    80  	return
    81  }
    82  
    83  // CreateAndUpdatePreparer prepares the CreateAndUpdate request.
    84  func (client ComponentLinkedStorageAccountsClient) CreateAndUpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, linkedStorageAccountsProperties ComponentLinkedStorageAccounts) (*http.Request, error) {
    85  	pathParameters := map[string]interface{}{
    86  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    87  		"resourceName":      autorest.Encode("path", resourceName),
    88  		"storageType":       autorest.Encode("path", "ServiceProfiler"),
    89  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    90  	}
    91  
    92  	const APIVersion = "2020-03-01-preview"
    93  	queryParameters := map[string]interface{}{
    94  		"api-version": APIVersion,
    95  	}
    96  
    97  	preparer := autorest.CreatePreparer(
    98  		autorest.AsContentType("application/json; charset=utf-8"),
    99  		autorest.AsPut(),
   100  		autorest.WithBaseURL(client.BaseURI),
   101  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}/linkedStorageAccounts/{storageType}", pathParameters),
   102  		autorest.WithJSON(linkedStorageAccountsProperties),
   103  		autorest.WithQueryParameters(queryParameters))
   104  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   105  }
   106  
   107  // CreateAndUpdateSender sends the CreateAndUpdate request. The method will close the
   108  // http.Response Body if it receives an error.
   109  func (client ComponentLinkedStorageAccountsClient) CreateAndUpdateSender(req *http.Request) (*http.Response, error) {
   110  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   111  }
   112  
   113  // CreateAndUpdateResponder handles the response to the CreateAndUpdate request. The method always
   114  // closes the http.Response Body.
   115  func (client ComponentLinkedStorageAccountsClient) CreateAndUpdateResponder(resp *http.Response) (result ComponentLinkedStorageAccounts, err error) {
   116  	err = autorest.Respond(
   117  		resp,
   118  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   119  		autorest.ByUnmarshallingJSON(&result),
   120  		autorest.ByClosing())
   121  	result.Response = autorest.Response{Response: resp}
   122  	return
   123  }
   124  
   125  // Delete delete linked storage accounts for an Application Insights component.
   126  // Parameters:
   127  // resourceGroupName - the name of the resource group. The name is case insensitive.
   128  // resourceName - the name of the Application Insights component resource.
   129  func (client ComponentLinkedStorageAccountsClient) Delete(ctx context.Context, resourceGroupName string, resourceName string) (result autorest.Response, err error) {
   130  	if tracing.IsEnabled() {
   131  		ctx = tracing.StartSpan(ctx, fqdn+"/ComponentLinkedStorageAccountsClient.Delete")
   132  		defer func() {
   133  			sc := -1
   134  			if result.Response != nil {
   135  				sc = result.Response.StatusCode
   136  			}
   137  			tracing.EndSpan(ctx, sc, err)
   138  		}()
   139  	}
   140  	if err := validation.Validate([]validation.Validation{
   141  		{TargetValue: resourceGroupName,
   142  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   143  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   144  		{TargetValue: client.SubscriptionID,
   145  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   146  		return result, validation.NewError("insights.ComponentLinkedStorageAccountsClient", "Delete", err.Error())
   147  	}
   148  
   149  	req, err := client.DeletePreparer(ctx, resourceGroupName, resourceName)
   150  	if err != nil {
   151  		err = autorest.NewErrorWithError(err, "insights.ComponentLinkedStorageAccountsClient", "Delete", nil, "Failure preparing request")
   152  		return
   153  	}
   154  
   155  	resp, err := client.DeleteSender(req)
   156  	if err != nil {
   157  		result.Response = resp
   158  		err = autorest.NewErrorWithError(err, "insights.ComponentLinkedStorageAccountsClient", "Delete", resp, "Failure sending request")
   159  		return
   160  	}
   161  
   162  	result, err = client.DeleteResponder(resp)
   163  	if err != nil {
   164  		err = autorest.NewErrorWithError(err, "insights.ComponentLinkedStorageAccountsClient", "Delete", resp, "Failure responding to request")
   165  		return
   166  	}
   167  
   168  	return
   169  }
   170  
   171  // DeletePreparer prepares the Delete request.
   172  func (client ComponentLinkedStorageAccountsClient) DeletePreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
   173  	pathParameters := map[string]interface{}{
   174  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   175  		"resourceName":      autorest.Encode("path", resourceName),
   176  		"storageType":       autorest.Encode("path", "ServiceProfiler"),
   177  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   178  	}
   179  
   180  	const APIVersion = "2020-03-01-preview"
   181  	queryParameters := map[string]interface{}{
   182  		"api-version": APIVersion,
   183  	}
   184  
   185  	preparer := autorest.CreatePreparer(
   186  		autorest.AsDelete(),
   187  		autorest.WithBaseURL(client.BaseURI),
   188  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}/linkedStorageAccounts/{storageType}", pathParameters),
   189  		autorest.WithQueryParameters(queryParameters))
   190  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   191  }
   192  
   193  // DeleteSender sends the Delete request. The method will close the
   194  // http.Response Body if it receives an error.
   195  func (client ComponentLinkedStorageAccountsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   196  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   197  }
   198  
   199  // DeleteResponder handles the response to the Delete request. The method always
   200  // closes the http.Response Body.
   201  func (client ComponentLinkedStorageAccountsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   202  	err = autorest.Respond(
   203  		resp,
   204  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   205  		autorest.ByClosing())
   206  	result.Response = resp
   207  	return
   208  }
   209  
   210  // Get returns the current linked storage settings for an Application Insights component.
   211  // Parameters:
   212  // resourceGroupName - the name of the resource group. The name is case insensitive.
   213  // resourceName - the name of the Application Insights component resource.
   214  func (client ComponentLinkedStorageAccountsClient) Get(ctx context.Context, resourceGroupName string, resourceName string) (result ComponentLinkedStorageAccounts, err error) {
   215  	if tracing.IsEnabled() {
   216  		ctx = tracing.StartSpan(ctx, fqdn+"/ComponentLinkedStorageAccountsClient.Get")
   217  		defer func() {
   218  			sc := -1
   219  			if result.Response.Response != nil {
   220  				sc = result.Response.Response.StatusCode
   221  			}
   222  			tracing.EndSpan(ctx, sc, err)
   223  		}()
   224  	}
   225  	if err := validation.Validate([]validation.Validation{
   226  		{TargetValue: resourceGroupName,
   227  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   228  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   229  		{TargetValue: client.SubscriptionID,
   230  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   231  		return result, validation.NewError("insights.ComponentLinkedStorageAccountsClient", "Get", err.Error())
   232  	}
   233  
   234  	req, err := client.GetPreparer(ctx, resourceGroupName, resourceName)
   235  	if err != nil {
   236  		err = autorest.NewErrorWithError(err, "insights.ComponentLinkedStorageAccountsClient", "Get", nil, "Failure preparing request")
   237  		return
   238  	}
   239  
   240  	resp, err := client.GetSender(req)
   241  	if err != nil {
   242  		result.Response = autorest.Response{Response: resp}
   243  		err = autorest.NewErrorWithError(err, "insights.ComponentLinkedStorageAccountsClient", "Get", resp, "Failure sending request")
   244  		return
   245  	}
   246  
   247  	result, err = client.GetResponder(resp)
   248  	if err != nil {
   249  		err = autorest.NewErrorWithError(err, "insights.ComponentLinkedStorageAccountsClient", "Get", resp, "Failure responding to request")
   250  		return
   251  	}
   252  
   253  	return
   254  }
   255  
   256  // GetPreparer prepares the Get request.
   257  func (client ComponentLinkedStorageAccountsClient) GetPreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
   258  	pathParameters := map[string]interface{}{
   259  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   260  		"resourceName":      autorest.Encode("path", resourceName),
   261  		"storageType":       autorest.Encode("path", "ServiceProfiler"),
   262  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   263  	}
   264  
   265  	const APIVersion = "2020-03-01-preview"
   266  	queryParameters := map[string]interface{}{
   267  		"api-version": APIVersion,
   268  	}
   269  
   270  	preparer := autorest.CreatePreparer(
   271  		autorest.AsGet(),
   272  		autorest.WithBaseURL(client.BaseURI),
   273  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}/linkedStorageAccounts/{storageType}", pathParameters),
   274  		autorest.WithQueryParameters(queryParameters))
   275  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   276  }
   277  
   278  // GetSender sends the Get request. The method will close the
   279  // http.Response Body if it receives an error.
   280  func (client ComponentLinkedStorageAccountsClient) GetSender(req *http.Request) (*http.Response, error) {
   281  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   282  }
   283  
   284  // GetResponder handles the response to the Get request. The method always
   285  // closes the http.Response Body.
   286  func (client ComponentLinkedStorageAccountsClient) GetResponder(resp *http.Response) (result ComponentLinkedStorageAccounts, err error) {
   287  	err = autorest.Respond(
   288  		resp,
   289  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   290  		autorest.ByUnmarshallingJSON(&result),
   291  		autorest.ByClosing())
   292  	result.Response = autorest.Response{Response: resp}
   293  	return
   294  }
   295  
   296  // Update update linked storage accounts for an Application Insights component.
   297  // Parameters:
   298  // resourceGroupName - the name of the resource group. The name is case insensitive.
   299  // resourceName - the name of the Application Insights component resource.
   300  // linkedStorageAccountsProperties - properties that need to be specified to update a linked storage accounts
   301  // for an Application Insights component.
   302  func (client ComponentLinkedStorageAccountsClient) Update(ctx context.Context, resourceGroupName string, resourceName string, linkedStorageAccountsProperties ComponentLinkedStorageAccountsPatch) (result ComponentLinkedStorageAccounts, err error) {
   303  	if tracing.IsEnabled() {
   304  		ctx = tracing.StartSpan(ctx, fqdn+"/ComponentLinkedStorageAccountsClient.Update")
   305  		defer func() {
   306  			sc := -1
   307  			if result.Response.Response != nil {
   308  				sc = result.Response.Response.StatusCode
   309  			}
   310  			tracing.EndSpan(ctx, sc, err)
   311  		}()
   312  	}
   313  	if err := validation.Validate([]validation.Validation{
   314  		{TargetValue: resourceGroupName,
   315  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   316  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   317  		{TargetValue: client.SubscriptionID,
   318  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   319  		return result, validation.NewError("insights.ComponentLinkedStorageAccountsClient", "Update", err.Error())
   320  	}
   321  
   322  	req, err := client.UpdatePreparer(ctx, resourceGroupName, resourceName, linkedStorageAccountsProperties)
   323  	if err != nil {
   324  		err = autorest.NewErrorWithError(err, "insights.ComponentLinkedStorageAccountsClient", "Update", nil, "Failure preparing request")
   325  		return
   326  	}
   327  
   328  	resp, err := client.UpdateSender(req)
   329  	if err != nil {
   330  		result.Response = autorest.Response{Response: resp}
   331  		err = autorest.NewErrorWithError(err, "insights.ComponentLinkedStorageAccountsClient", "Update", resp, "Failure sending request")
   332  		return
   333  	}
   334  
   335  	result, err = client.UpdateResponder(resp)
   336  	if err != nil {
   337  		err = autorest.NewErrorWithError(err, "insights.ComponentLinkedStorageAccountsClient", "Update", resp, "Failure responding to request")
   338  		return
   339  	}
   340  
   341  	return
   342  }
   343  
   344  // UpdatePreparer prepares the Update request.
   345  func (client ComponentLinkedStorageAccountsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, linkedStorageAccountsProperties ComponentLinkedStorageAccountsPatch) (*http.Request, error) {
   346  	pathParameters := map[string]interface{}{
   347  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   348  		"resourceName":      autorest.Encode("path", resourceName),
   349  		"storageType":       autorest.Encode("path", "ServiceProfiler"),
   350  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   351  	}
   352  
   353  	const APIVersion = "2020-03-01-preview"
   354  	queryParameters := map[string]interface{}{
   355  		"api-version": APIVersion,
   356  	}
   357  
   358  	preparer := autorest.CreatePreparer(
   359  		autorest.AsContentType("application/json; charset=utf-8"),
   360  		autorest.AsPatch(),
   361  		autorest.WithBaseURL(client.BaseURI),
   362  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}/linkedStorageAccounts/{storageType}", pathParameters),
   363  		autorest.WithJSON(linkedStorageAccountsProperties),
   364  		autorest.WithQueryParameters(queryParameters))
   365  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   366  }
   367  
   368  // UpdateSender sends the Update request. The method will close the
   369  // http.Response Body if it receives an error.
   370  func (client ComponentLinkedStorageAccountsClient) UpdateSender(req *http.Request) (*http.Response, error) {
   371  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   372  }
   373  
   374  // UpdateResponder handles the response to the Update request. The method always
   375  // closes the http.Response Body.
   376  func (client ComponentLinkedStorageAccountsClient) UpdateResponder(resp *http.Response) (result ComponentLinkedStorageAccounts, err error) {
   377  	err = autorest.Respond(
   378  		resp,
   379  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   380  		autorest.ByUnmarshallingJSON(&result),
   381  		autorest.ByClosing())
   382  	result.Response = autorest.Response{Response: resp}
   383  	return
   384  }
   385  

View as plain text