...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/appinsights/mgmt/2021-11-01-preview/insights/apikeys.go

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

View as plain text