...

Source file src/github.com/Azure/azure-sdk-for-go/services/appinsights/mgmt/2015-05-01/insights/myworkbooks.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  // MyWorkbooksClient is the composite Swagger for Application Insights Management Client
    19  type MyWorkbooksClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewMyWorkbooksClient creates an instance of the MyWorkbooksClient client.
    24  func NewMyWorkbooksClient(subscriptionID string) MyWorkbooksClient {
    25  	return NewMyWorkbooksClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewMyWorkbooksClientWithBaseURI creates an instance of the MyWorkbooksClient client using a custom endpoint.  Use
    29  // this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewMyWorkbooksClientWithBaseURI(baseURI string, subscriptionID string) MyWorkbooksClient {
    31  	return MyWorkbooksClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate create a new private workbook.
    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  // workbookProperties - properties that need to be specified to create a new private workbook.
    39  func (client MyWorkbooksClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, resourceName string, workbookProperties MyWorkbook) (result MyWorkbook, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/MyWorkbooksClient.CreateOrUpdate")
    42  		defer func() {
    43  			sc := -1
    44  			if result.Response.Response != nil {
    45  				sc = result.Response.Response.StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	if err := validation.Validate([]validation.Validation{
    51  		{TargetValue: client.SubscriptionID,
    52  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    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  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
    57  		{TargetValue: workbookProperties,
    58  			Constraints: []validation.Constraint{{Target: "workbookProperties.MyWorkbookProperties", Name: validation.Null, Rule: false,
    59  				Chain: []validation.Constraint{{Target: "workbookProperties.MyWorkbookProperties.DisplayName", Name: validation.Null, Rule: true, Chain: nil},
    60  					{Target: "workbookProperties.MyWorkbookProperties.SerializedData", Name: validation.Null, Rule: true, Chain: nil},
    61  					{Target: "workbookProperties.MyWorkbookProperties.Category", Name: validation.Null, Rule: true, Chain: nil},
    62  				}}}}}); err != nil {
    63  		return result, validation.NewError("insights.MyWorkbooksClient", "CreateOrUpdate", err.Error())
    64  	}
    65  
    66  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, resourceName, workbookProperties)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "CreateOrUpdate", nil, "Failure preparing request")
    69  		return
    70  	}
    71  
    72  	resp, err := client.CreateOrUpdateSender(req)
    73  	if err != nil {
    74  		result.Response = autorest.Response{Response: resp}
    75  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "CreateOrUpdate", resp, "Failure sending request")
    76  		return
    77  	}
    78  
    79  	result, err = client.CreateOrUpdateResponder(resp)
    80  	if err != nil {
    81  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "CreateOrUpdate", resp, "Failure responding to request")
    82  		return
    83  	}
    84  
    85  	return
    86  }
    87  
    88  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    89  func (client MyWorkbooksClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, workbookProperties MyWorkbook) (*http.Request, error) {
    90  	pathParameters := map[string]interface{}{
    91  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    92  		"resourceName":      autorest.Encode("path", resourceName),
    93  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    94  	}
    95  
    96  	const APIVersion = "2015-05-01"
    97  	queryParameters := map[string]interface{}{
    98  		"api-version": APIVersion,
    99  	}
   100  
   101  	preparer := autorest.CreatePreparer(
   102  		autorest.AsContentType("application/json; charset=utf-8"),
   103  		autorest.AsPut(),
   104  		autorest.WithBaseURL(client.BaseURI),
   105  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/myWorkbooks/{resourceName}", pathParameters),
   106  		autorest.WithJSON(workbookProperties),
   107  		autorest.WithQueryParameters(queryParameters))
   108  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   109  }
   110  
   111  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   112  // http.Response Body if it receives an error.
   113  func (client MyWorkbooksClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   114  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   115  }
   116  
   117  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   118  // closes the http.Response Body.
   119  func (client MyWorkbooksClient) CreateOrUpdateResponder(resp *http.Response) (result MyWorkbook, err error) {
   120  	err = autorest.Respond(
   121  		resp,
   122  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   123  		autorest.ByUnmarshallingJSON(&result),
   124  		autorest.ByClosing())
   125  	result.Response = autorest.Response{Response: resp}
   126  	return
   127  }
   128  
   129  // Delete delete a private workbook.
   130  // Parameters:
   131  // resourceGroupName - the name of the resource group. The name is case insensitive.
   132  // resourceName - the name of the Application Insights component resource.
   133  func (client MyWorkbooksClient) Delete(ctx context.Context, resourceGroupName string, resourceName string) (result autorest.Response, err error) {
   134  	if tracing.IsEnabled() {
   135  		ctx = tracing.StartSpan(ctx, fqdn+"/MyWorkbooksClient.Delete")
   136  		defer func() {
   137  			sc := -1
   138  			if result.Response != nil {
   139  				sc = result.Response.StatusCode
   140  			}
   141  			tracing.EndSpan(ctx, sc, err)
   142  		}()
   143  	}
   144  	if err := validation.Validate([]validation.Validation{
   145  		{TargetValue: client.SubscriptionID,
   146  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   147  		{TargetValue: resourceGroupName,
   148  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   149  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   150  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   151  		return result, validation.NewError("insights.MyWorkbooksClient", "Delete", err.Error())
   152  	}
   153  
   154  	req, err := client.DeletePreparer(ctx, resourceGroupName, resourceName)
   155  	if err != nil {
   156  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "Delete", nil, "Failure preparing request")
   157  		return
   158  	}
   159  
   160  	resp, err := client.DeleteSender(req)
   161  	if err != nil {
   162  		result.Response = resp
   163  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "Delete", resp, "Failure sending request")
   164  		return
   165  	}
   166  
   167  	result, err = client.DeleteResponder(resp)
   168  	if err != nil {
   169  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "Delete", resp, "Failure responding to request")
   170  		return
   171  	}
   172  
   173  	return
   174  }
   175  
   176  // DeletePreparer prepares the Delete request.
   177  func (client MyWorkbooksClient) DeletePreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
   178  	pathParameters := map[string]interface{}{
   179  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   180  		"resourceName":      autorest.Encode("path", resourceName),
   181  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   182  	}
   183  
   184  	const APIVersion = "2015-05-01"
   185  	queryParameters := map[string]interface{}{
   186  		"api-version": APIVersion,
   187  	}
   188  
   189  	preparer := autorest.CreatePreparer(
   190  		autorest.AsDelete(),
   191  		autorest.WithBaseURL(client.BaseURI),
   192  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/myWorkbooks/{resourceName}", pathParameters),
   193  		autorest.WithQueryParameters(queryParameters))
   194  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   195  }
   196  
   197  // DeleteSender sends the Delete request. The method will close the
   198  // http.Response Body if it receives an error.
   199  func (client MyWorkbooksClient) DeleteSender(req *http.Request) (*http.Response, error) {
   200  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   201  }
   202  
   203  // DeleteResponder handles the response to the Delete request. The method always
   204  // closes the http.Response Body.
   205  func (client MyWorkbooksClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   206  	err = autorest.Respond(
   207  		resp,
   208  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusNoContent),
   209  		autorest.ByClosing())
   210  	result.Response = resp
   211  	return
   212  }
   213  
   214  // Get get a single private workbook by its resourceName.
   215  // Parameters:
   216  // resourceGroupName - the name of the resource group. The name is case insensitive.
   217  // resourceName - the name of the Application Insights component resource.
   218  func (client MyWorkbooksClient) Get(ctx context.Context, resourceGroupName string, resourceName string) (result MyWorkbook, err error) {
   219  	if tracing.IsEnabled() {
   220  		ctx = tracing.StartSpan(ctx, fqdn+"/MyWorkbooksClient.Get")
   221  		defer func() {
   222  			sc := -1
   223  			if result.Response.Response != nil {
   224  				sc = result.Response.Response.StatusCode
   225  			}
   226  			tracing.EndSpan(ctx, sc, err)
   227  		}()
   228  	}
   229  	if err := validation.Validate([]validation.Validation{
   230  		{TargetValue: client.SubscriptionID,
   231  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   232  		{TargetValue: resourceGroupName,
   233  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   234  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   235  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   236  		return result, validation.NewError("insights.MyWorkbooksClient", "Get", err.Error())
   237  	}
   238  
   239  	req, err := client.GetPreparer(ctx, resourceGroupName, resourceName)
   240  	if err != nil {
   241  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "Get", nil, "Failure preparing request")
   242  		return
   243  	}
   244  
   245  	resp, err := client.GetSender(req)
   246  	if err != nil {
   247  		result.Response = autorest.Response{Response: resp}
   248  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "Get", resp, "Failure sending request")
   249  		return
   250  	}
   251  
   252  	result, err = client.GetResponder(resp)
   253  	if err != nil {
   254  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "Get", resp, "Failure responding to request")
   255  		return
   256  	}
   257  
   258  	return
   259  }
   260  
   261  // GetPreparer prepares the Get request.
   262  func (client MyWorkbooksClient) GetPreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
   263  	pathParameters := map[string]interface{}{
   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/myWorkbooks/{resourceName}", 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 MyWorkbooksClient) 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 MyWorkbooksClient) GetResponder(resp *http.Response) (result MyWorkbook, 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  // ListByResourceGroup get all private workbooks defined within a specified resource group and category.
   301  // Parameters:
   302  // resourceGroupName - the name of the resource group. The name is case insensitive.
   303  // category - category of workbook to return.
   304  // tags - tags presents on each workbook returned.
   305  // canFetchContent - flag indicating whether or not to return the full content for each applicable workbook. If
   306  // false, only return summary content for workbooks.
   307  func (client MyWorkbooksClient) ListByResourceGroup(ctx context.Context, resourceGroupName string, category CategoryType, tags []string, canFetchContent *bool) (result MyWorkbooksListResult, err error) {
   308  	if tracing.IsEnabled() {
   309  		ctx = tracing.StartSpan(ctx, fqdn+"/MyWorkbooksClient.ListByResourceGroup")
   310  		defer func() {
   311  			sc := -1
   312  			if result.Response.Response != nil {
   313  				sc = result.Response.Response.StatusCode
   314  			}
   315  			tracing.EndSpan(ctx, sc, err)
   316  		}()
   317  	}
   318  	if err := validation.Validate([]validation.Validation{
   319  		{TargetValue: client.SubscriptionID,
   320  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   321  		{TargetValue: resourceGroupName,
   322  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   323  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   324  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   325  		return result, validation.NewError("insights.MyWorkbooksClient", "ListByResourceGroup", err.Error())
   326  	}
   327  
   328  	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName, category, tags, canFetchContent)
   329  	if err != nil {
   330  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "ListByResourceGroup", nil, "Failure preparing request")
   331  		return
   332  	}
   333  
   334  	resp, err := client.ListByResourceGroupSender(req)
   335  	if err != nil {
   336  		result.Response = autorest.Response{Response: resp}
   337  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "ListByResourceGroup", resp, "Failure sending request")
   338  		return
   339  	}
   340  
   341  	result, err = client.ListByResourceGroupResponder(resp)
   342  	if err != nil {
   343  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "ListByResourceGroup", resp, "Failure responding to request")
   344  		return
   345  	}
   346  
   347  	return
   348  }
   349  
   350  // ListByResourceGroupPreparer prepares the ListByResourceGroup request.
   351  func (client MyWorkbooksClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string, category CategoryType, tags []string, canFetchContent *bool) (*http.Request, error) {
   352  	pathParameters := map[string]interface{}{
   353  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   354  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   355  	}
   356  
   357  	const APIVersion = "2015-05-01"
   358  	queryParameters := map[string]interface{}{
   359  		"api-version": APIVersion,
   360  		"category":    autorest.Encode("query", category),
   361  	}
   362  	if tags != nil && len(tags) > 0 {
   363  		queryParameters["tags"] = autorest.Encode("query", tags, ",")
   364  	}
   365  	if canFetchContent != nil {
   366  		queryParameters["canFetchContent"] = autorest.Encode("query", *canFetchContent)
   367  	}
   368  
   369  	preparer := autorest.CreatePreparer(
   370  		autorest.AsGet(),
   371  		autorest.WithBaseURL(client.BaseURI),
   372  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/myWorkbooks", pathParameters),
   373  		autorest.WithQueryParameters(queryParameters))
   374  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   375  }
   376  
   377  // ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
   378  // http.Response Body if it receives an error.
   379  func (client MyWorkbooksClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
   380  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   381  }
   382  
   383  // ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
   384  // closes the http.Response Body.
   385  func (client MyWorkbooksClient) ListByResourceGroupResponder(resp *http.Response) (result MyWorkbooksListResult, err error) {
   386  	err = autorest.Respond(
   387  		resp,
   388  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   389  		autorest.ByUnmarshallingJSON(&result),
   390  		autorest.ByClosing())
   391  	result.Response = autorest.Response{Response: resp}
   392  	return
   393  }
   394  
   395  // ListBySubscription get all private workbooks defined within a specified subscription and category.
   396  // Parameters:
   397  // category - category of workbook to return.
   398  // tags - tags presents on each workbook returned.
   399  // canFetchContent - flag indicating whether or not to return the full content for each applicable workbook. If
   400  // false, only return summary content for workbooks.
   401  func (client MyWorkbooksClient) ListBySubscription(ctx context.Context, category CategoryType, tags []string, canFetchContent *bool) (result MyWorkbooksListResult, err error) {
   402  	if tracing.IsEnabled() {
   403  		ctx = tracing.StartSpan(ctx, fqdn+"/MyWorkbooksClient.ListBySubscription")
   404  		defer func() {
   405  			sc := -1
   406  			if result.Response.Response != nil {
   407  				sc = result.Response.Response.StatusCode
   408  			}
   409  			tracing.EndSpan(ctx, sc, err)
   410  		}()
   411  	}
   412  	if err := validation.Validate([]validation.Validation{
   413  		{TargetValue: client.SubscriptionID,
   414  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   415  		return result, validation.NewError("insights.MyWorkbooksClient", "ListBySubscription", err.Error())
   416  	}
   417  
   418  	req, err := client.ListBySubscriptionPreparer(ctx, category, tags, canFetchContent)
   419  	if err != nil {
   420  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "ListBySubscription", nil, "Failure preparing request")
   421  		return
   422  	}
   423  
   424  	resp, err := client.ListBySubscriptionSender(req)
   425  	if err != nil {
   426  		result.Response = autorest.Response{Response: resp}
   427  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "ListBySubscription", resp, "Failure sending request")
   428  		return
   429  	}
   430  
   431  	result, err = client.ListBySubscriptionResponder(resp)
   432  	if err != nil {
   433  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "ListBySubscription", resp, "Failure responding to request")
   434  		return
   435  	}
   436  
   437  	return
   438  }
   439  
   440  // ListBySubscriptionPreparer prepares the ListBySubscription request.
   441  func (client MyWorkbooksClient) ListBySubscriptionPreparer(ctx context.Context, category CategoryType, tags []string, canFetchContent *bool) (*http.Request, error) {
   442  	pathParameters := map[string]interface{}{
   443  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   444  	}
   445  
   446  	const APIVersion = "2015-05-01"
   447  	queryParameters := map[string]interface{}{
   448  		"api-version": APIVersion,
   449  		"category":    autorest.Encode("query", category),
   450  	}
   451  	if tags != nil && len(tags) > 0 {
   452  		queryParameters["tags"] = autorest.Encode("query", tags, ",")
   453  	}
   454  	if canFetchContent != nil {
   455  		queryParameters["canFetchContent"] = autorest.Encode("query", *canFetchContent)
   456  	}
   457  
   458  	preparer := autorest.CreatePreparer(
   459  		autorest.AsGet(),
   460  		autorest.WithBaseURL(client.BaseURI),
   461  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Insights/myWorkbooks", pathParameters),
   462  		autorest.WithQueryParameters(queryParameters))
   463  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   464  }
   465  
   466  // ListBySubscriptionSender sends the ListBySubscription request. The method will close the
   467  // http.Response Body if it receives an error.
   468  func (client MyWorkbooksClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
   469  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   470  }
   471  
   472  // ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
   473  // closes the http.Response Body.
   474  func (client MyWorkbooksClient) ListBySubscriptionResponder(resp *http.Response) (result MyWorkbooksListResult, err error) {
   475  	err = autorest.Respond(
   476  		resp,
   477  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   478  		autorest.ByUnmarshallingJSON(&result),
   479  		autorest.ByClosing())
   480  	result.Response = autorest.Response{Response: resp}
   481  	return
   482  }
   483  
   484  // Update updates a private workbook that has already been added.
   485  // Parameters:
   486  // resourceGroupName - the name of the resource group. The name is case insensitive.
   487  // resourceName - the name of the Application Insights component resource.
   488  // workbookProperties - properties that need to be specified to create a new private workbook.
   489  func (client MyWorkbooksClient) Update(ctx context.Context, resourceGroupName string, resourceName string, workbookProperties MyWorkbook) (result MyWorkbook, err error) {
   490  	if tracing.IsEnabled() {
   491  		ctx = tracing.StartSpan(ctx, fqdn+"/MyWorkbooksClient.Update")
   492  		defer func() {
   493  			sc := -1
   494  			if result.Response.Response != nil {
   495  				sc = result.Response.Response.StatusCode
   496  			}
   497  			tracing.EndSpan(ctx, sc, err)
   498  		}()
   499  	}
   500  	if err := validation.Validate([]validation.Validation{
   501  		{TargetValue: client.SubscriptionID,
   502  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   503  		{TargetValue: resourceGroupName,
   504  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   505  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   506  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   507  		return result, validation.NewError("insights.MyWorkbooksClient", "Update", err.Error())
   508  	}
   509  
   510  	req, err := client.UpdatePreparer(ctx, resourceGroupName, resourceName, workbookProperties)
   511  	if err != nil {
   512  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "Update", nil, "Failure preparing request")
   513  		return
   514  	}
   515  
   516  	resp, err := client.UpdateSender(req)
   517  	if err != nil {
   518  		result.Response = autorest.Response{Response: resp}
   519  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "Update", resp, "Failure sending request")
   520  		return
   521  	}
   522  
   523  	result, err = client.UpdateResponder(resp)
   524  	if err != nil {
   525  		err = autorest.NewErrorWithError(err, "insights.MyWorkbooksClient", "Update", resp, "Failure responding to request")
   526  		return
   527  	}
   528  
   529  	return
   530  }
   531  
   532  // UpdatePreparer prepares the Update request.
   533  func (client MyWorkbooksClient) UpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, workbookProperties MyWorkbook) (*http.Request, error) {
   534  	pathParameters := map[string]interface{}{
   535  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   536  		"resourceName":      autorest.Encode("path", resourceName),
   537  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   538  	}
   539  
   540  	const APIVersion = "2015-05-01"
   541  	queryParameters := map[string]interface{}{
   542  		"api-version": APIVersion,
   543  	}
   544  
   545  	preparer := autorest.CreatePreparer(
   546  		autorest.AsContentType("application/json; charset=utf-8"),
   547  		autorest.AsPatch(),
   548  		autorest.WithBaseURL(client.BaseURI),
   549  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/myWorkbooks/{resourceName}", pathParameters),
   550  		autorest.WithJSON(workbookProperties),
   551  		autorest.WithQueryParameters(queryParameters))
   552  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   553  }
   554  
   555  // UpdateSender sends the Update request. The method will close the
   556  // http.Response Body if it receives an error.
   557  func (client MyWorkbooksClient) UpdateSender(req *http.Request) (*http.Response, error) {
   558  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   559  }
   560  
   561  // UpdateResponder handles the response to the Update request. The method always
   562  // closes the http.Response Body.
   563  func (client MyWorkbooksClient) UpdateResponder(resp *http.Response) (result MyWorkbook, err error) {
   564  	err = autorest.Respond(
   565  		resp,
   566  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   567  		autorest.ByUnmarshallingJSON(&result),
   568  		autorest.ByClosing())
   569  	result.Response = autorest.Response{Response: resp}
   570  	return
   571  }
   572  

View as plain text