...

Source file src/github.com/Azure/azure-sdk-for-go/services/appinsights/mgmt/2015-05-01/insights/apikeys.go

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