...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-07-01-preview/insights/actiongroups.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-07-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  // ActionGroupsClient is the monitor Management Client
    19  type ActionGroupsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewActionGroupsClient creates an instance of the ActionGroupsClient client.
    24  func NewActionGroupsClient(subscriptionID string) ActionGroupsClient {
    25  	return NewActionGroupsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewActionGroupsClientWithBaseURI creates an instance of the ActionGroupsClient 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 NewActionGroupsClientWithBaseURI(baseURI string, subscriptionID string) ActionGroupsClient {
    31  	return ActionGroupsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate create a new action group or update an existing one.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group. The name is case insensitive.
    37  // actionGroupName - the name of the action group.
    38  // actionGroup - the action group to create or use for the update.
    39  func (client ActionGroupsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, actionGroupName string, actionGroup ActionGroupResource) (result ActionGroupResource, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/ActionGroupsClient.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: resourceGroupName,
    52  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    53  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    54  		{TargetValue: actionGroup,
    55  			Constraints: []validation.Constraint{{Target: "actionGroup.ActionGroup", Name: validation.Null, Rule: false,
    56  				Chain: []validation.Constraint{{Target: "actionGroup.ActionGroup.GroupShortName", Name: validation.Null, Rule: true,
    57  					Chain: []validation.Constraint{{Target: "actionGroup.ActionGroup.GroupShortName", Name: validation.MaxLength, Rule: 12, Chain: nil}}},
    58  					{Target: "actionGroup.ActionGroup.Enabled", Name: validation.Null, Rule: true, Chain: nil},
    59  				}}}},
    60  		{TargetValue: client.SubscriptionID,
    61  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
    62  		return result, validation.NewError("insights.ActionGroupsClient", "CreateOrUpdate", err.Error())
    63  	}
    64  
    65  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, actionGroupName, actionGroup)
    66  	if err != nil {
    67  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "CreateOrUpdate", nil, "Failure preparing request")
    68  		return
    69  	}
    70  
    71  	resp, err := client.CreateOrUpdateSender(req)
    72  	if err != nil {
    73  		result.Response = autorest.Response{Response: resp}
    74  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "CreateOrUpdate", resp, "Failure sending request")
    75  		return
    76  	}
    77  
    78  	result, err = client.CreateOrUpdateResponder(resp)
    79  	if err != nil {
    80  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "CreateOrUpdate", resp, "Failure responding to request")
    81  		return
    82  	}
    83  
    84  	return
    85  }
    86  
    87  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    88  func (client ActionGroupsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, actionGroupName string, actionGroup ActionGroupResource) (*http.Request, error) {
    89  	pathParameters := map[string]interface{}{
    90  		"actionGroupName":   autorest.Encode("path", actionGroupName),
    91  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    92  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    93  	}
    94  
    95  	const APIVersion = "2019-06-01"
    96  	queryParameters := map[string]interface{}{
    97  		"api-version": APIVersion,
    98  	}
    99  
   100  	preparer := autorest.CreatePreparer(
   101  		autorest.AsContentType("application/json; charset=utf-8"),
   102  		autorest.AsPut(),
   103  		autorest.WithBaseURL(client.BaseURI),
   104  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/actionGroups/{actionGroupName}", pathParameters),
   105  		autorest.WithJSON(actionGroup),
   106  		autorest.WithQueryParameters(queryParameters))
   107  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   108  }
   109  
   110  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   111  // http.Response Body if it receives an error.
   112  func (client ActionGroupsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   113  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   114  }
   115  
   116  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   117  // closes the http.Response Body.
   118  func (client ActionGroupsClient) CreateOrUpdateResponder(resp *http.Response) (result ActionGroupResource, err error) {
   119  	err = autorest.Respond(
   120  		resp,
   121  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   122  		autorest.ByUnmarshallingJSON(&result),
   123  		autorest.ByClosing())
   124  	result.Response = autorest.Response{Response: resp}
   125  	return
   126  }
   127  
   128  // Delete delete an action group.
   129  // Parameters:
   130  // resourceGroupName - the name of the resource group. The name is case insensitive.
   131  // actionGroupName - the name of the action group.
   132  func (client ActionGroupsClient) Delete(ctx context.Context, resourceGroupName string, actionGroupName string) (result autorest.Response, err error) {
   133  	if tracing.IsEnabled() {
   134  		ctx = tracing.StartSpan(ctx, fqdn+"/ActionGroupsClient.Delete")
   135  		defer func() {
   136  			sc := -1
   137  			if result.Response != nil {
   138  				sc = result.Response.StatusCode
   139  			}
   140  			tracing.EndSpan(ctx, sc, err)
   141  		}()
   142  	}
   143  	if err := validation.Validate([]validation.Validation{
   144  		{TargetValue: resourceGroupName,
   145  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   146  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   147  		{TargetValue: client.SubscriptionID,
   148  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   149  		return result, validation.NewError("insights.ActionGroupsClient", "Delete", err.Error())
   150  	}
   151  
   152  	req, err := client.DeletePreparer(ctx, resourceGroupName, actionGroupName)
   153  	if err != nil {
   154  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "Delete", nil, "Failure preparing request")
   155  		return
   156  	}
   157  
   158  	resp, err := client.DeleteSender(req)
   159  	if err != nil {
   160  		result.Response = resp
   161  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "Delete", resp, "Failure sending request")
   162  		return
   163  	}
   164  
   165  	result, err = client.DeleteResponder(resp)
   166  	if err != nil {
   167  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "Delete", resp, "Failure responding to request")
   168  		return
   169  	}
   170  
   171  	return
   172  }
   173  
   174  // DeletePreparer prepares the Delete request.
   175  func (client ActionGroupsClient) DeletePreparer(ctx context.Context, resourceGroupName string, actionGroupName string) (*http.Request, error) {
   176  	pathParameters := map[string]interface{}{
   177  		"actionGroupName":   autorest.Encode("path", actionGroupName),
   178  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   179  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   180  	}
   181  
   182  	const APIVersion = "2019-06-01"
   183  	queryParameters := map[string]interface{}{
   184  		"api-version": APIVersion,
   185  	}
   186  
   187  	preparer := autorest.CreatePreparer(
   188  		autorest.AsDelete(),
   189  		autorest.WithBaseURL(client.BaseURI),
   190  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/actionGroups/{actionGroupName}", pathParameters),
   191  		autorest.WithQueryParameters(queryParameters))
   192  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   193  }
   194  
   195  // DeleteSender sends the Delete request. The method will close the
   196  // http.Response Body if it receives an error.
   197  func (client ActionGroupsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   198  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   199  }
   200  
   201  // DeleteResponder handles the response to the Delete request. The method always
   202  // closes the http.Response Body.
   203  func (client ActionGroupsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   204  	err = autorest.Respond(
   205  		resp,
   206  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   207  		autorest.ByClosing())
   208  	result.Response = resp
   209  	return
   210  }
   211  
   212  // EnableReceiver enable a receiver in an action group. This changes the receiver's status from Disabled to Enabled.
   213  // This operation is only supported for Email or SMS receivers.
   214  // Parameters:
   215  // resourceGroupName - the name of the resource group. The name is case insensitive.
   216  // actionGroupName - the name of the action group.
   217  // enableRequest - the receiver to re-enable.
   218  func (client ActionGroupsClient) EnableReceiver(ctx context.Context, resourceGroupName string, actionGroupName string, enableRequest EnableRequest) (result autorest.Response, err error) {
   219  	if tracing.IsEnabled() {
   220  		ctx = tracing.StartSpan(ctx, fqdn+"/ActionGroupsClient.EnableReceiver")
   221  		defer func() {
   222  			sc := -1
   223  			if result.Response != nil {
   224  				sc = result.Response.StatusCode
   225  			}
   226  			tracing.EndSpan(ctx, sc, err)
   227  		}()
   228  	}
   229  	if err := validation.Validate([]validation.Validation{
   230  		{TargetValue: resourceGroupName,
   231  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   232  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   233  		{TargetValue: enableRequest,
   234  			Constraints: []validation.Constraint{{Target: "enableRequest.ReceiverName", Name: validation.Null, Rule: true, Chain: nil}}},
   235  		{TargetValue: client.SubscriptionID,
   236  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   237  		return result, validation.NewError("insights.ActionGroupsClient", "EnableReceiver", err.Error())
   238  	}
   239  
   240  	req, err := client.EnableReceiverPreparer(ctx, resourceGroupName, actionGroupName, enableRequest)
   241  	if err != nil {
   242  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "EnableReceiver", nil, "Failure preparing request")
   243  		return
   244  	}
   245  
   246  	resp, err := client.EnableReceiverSender(req)
   247  	if err != nil {
   248  		result.Response = resp
   249  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "EnableReceiver", resp, "Failure sending request")
   250  		return
   251  	}
   252  
   253  	result, err = client.EnableReceiverResponder(resp)
   254  	if err != nil {
   255  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "EnableReceiver", resp, "Failure responding to request")
   256  		return
   257  	}
   258  
   259  	return
   260  }
   261  
   262  // EnableReceiverPreparer prepares the EnableReceiver request.
   263  func (client ActionGroupsClient) EnableReceiverPreparer(ctx context.Context, resourceGroupName string, actionGroupName string, enableRequest EnableRequest) (*http.Request, error) {
   264  	pathParameters := map[string]interface{}{
   265  		"actionGroupName":   autorest.Encode("path", actionGroupName),
   266  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   267  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   268  	}
   269  
   270  	const APIVersion = "2019-06-01"
   271  	queryParameters := map[string]interface{}{
   272  		"api-version": APIVersion,
   273  	}
   274  
   275  	preparer := autorest.CreatePreparer(
   276  		autorest.AsContentType("application/json; charset=utf-8"),
   277  		autorest.AsPost(),
   278  		autorest.WithBaseURL(client.BaseURI),
   279  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/actionGroups/{actionGroupName}/subscribe", pathParameters),
   280  		autorest.WithJSON(enableRequest),
   281  		autorest.WithQueryParameters(queryParameters))
   282  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   283  }
   284  
   285  // EnableReceiverSender sends the EnableReceiver request. The method will close the
   286  // http.Response Body if it receives an error.
   287  func (client ActionGroupsClient) EnableReceiverSender(req *http.Request) (*http.Response, error) {
   288  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   289  }
   290  
   291  // EnableReceiverResponder handles the response to the EnableReceiver request. The method always
   292  // closes the http.Response Body.
   293  func (client ActionGroupsClient) EnableReceiverResponder(resp *http.Response) (result autorest.Response, err error) {
   294  	err = autorest.Respond(
   295  		resp,
   296  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusConflict),
   297  		autorest.ByClosing())
   298  	result.Response = resp
   299  	return
   300  }
   301  
   302  // Get get an action group.
   303  // Parameters:
   304  // resourceGroupName - the name of the resource group. The name is case insensitive.
   305  // actionGroupName - the name of the action group.
   306  func (client ActionGroupsClient) Get(ctx context.Context, resourceGroupName string, actionGroupName string) (result ActionGroupResource, err error) {
   307  	if tracing.IsEnabled() {
   308  		ctx = tracing.StartSpan(ctx, fqdn+"/ActionGroupsClient.Get")
   309  		defer func() {
   310  			sc := -1
   311  			if result.Response.Response != nil {
   312  				sc = result.Response.Response.StatusCode
   313  			}
   314  			tracing.EndSpan(ctx, sc, err)
   315  		}()
   316  	}
   317  	if err := validation.Validate([]validation.Validation{
   318  		{TargetValue: resourceGroupName,
   319  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   320  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   321  		{TargetValue: client.SubscriptionID,
   322  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   323  		return result, validation.NewError("insights.ActionGroupsClient", "Get", err.Error())
   324  	}
   325  
   326  	req, err := client.GetPreparer(ctx, resourceGroupName, actionGroupName)
   327  	if err != nil {
   328  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "Get", nil, "Failure preparing request")
   329  		return
   330  	}
   331  
   332  	resp, err := client.GetSender(req)
   333  	if err != nil {
   334  		result.Response = autorest.Response{Response: resp}
   335  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "Get", resp, "Failure sending request")
   336  		return
   337  	}
   338  
   339  	result, err = client.GetResponder(resp)
   340  	if err != nil {
   341  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "Get", resp, "Failure responding to request")
   342  		return
   343  	}
   344  
   345  	return
   346  }
   347  
   348  // GetPreparer prepares the Get request.
   349  func (client ActionGroupsClient) GetPreparer(ctx context.Context, resourceGroupName string, actionGroupName string) (*http.Request, error) {
   350  	pathParameters := map[string]interface{}{
   351  		"actionGroupName":   autorest.Encode("path", actionGroupName),
   352  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   353  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   354  	}
   355  
   356  	const APIVersion = "2019-06-01"
   357  	queryParameters := map[string]interface{}{
   358  		"api-version": APIVersion,
   359  	}
   360  
   361  	preparer := autorest.CreatePreparer(
   362  		autorest.AsGet(),
   363  		autorest.WithBaseURL(client.BaseURI),
   364  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/actionGroups/{actionGroupName}", pathParameters),
   365  		autorest.WithQueryParameters(queryParameters))
   366  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   367  }
   368  
   369  // GetSender sends the Get request. The method will close the
   370  // http.Response Body if it receives an error.
   371  func (client ActionGroupsClient) GetSender(req *http.Request) (*http.Response, error) {
   372  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   373  }
   374  
   375  // GetResponder handles the response to the Get request. The method always
   376  // closes the http.Response Body.
   377  func (client ActionGroupsClient) GetResponder(resp *http.Response) (result ActionGroupResource, err error) {
   378  	err = autorest.Respond(
   379  		resp,
   380  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   381  		autorest.ByUnmarshallingJSON(&result),
   382  		autorest.ByClosing())
   383  	result.Response = autorest.Response{Response: resp}
   384  	return
   385  }
   386  
   387  // ListByResourceGroup get a list of all action groups in a resource group.
   388  // Parameters:
   389  // resourceGroupName - the name of the resource group. The name is case insensitive.
   390  func (client ActionGroupsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ActionGroupList, err error) {
   391  	if tracing.IsEnabled() {
   392  		ctx = tracing.StartSpan(ctx, fqdn+"/ActionGroupsClient.ListByResourceGroup")
   393  		defer func() {
   394  			sc := -1
   395  			if result.Response.Response != nil {
   396  				sc = result.Response.Response.StatusCode
   397  			}
   398  			tracing.EndSpan(ctx, sc, err)
   399  		}()
   400  	}
   401  	if err := validation.Validate([]validation.Validation{
   402  		{TargetValue: resourceGroupName,
   403  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   404  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   405  		{TargetValue: client.SubscriptionID,
   406  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   407  		return result, validation.NewError("insights.ActionGroupsClient", "ListByResourceGroup", err.Error())
   408  	}
   409  
   410  	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
   411  	if err != nil {
   412  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "ListByResourceGroup", nil, "Failure preparing request")
   413  		return
   414  	}
   415  
   416  	resp, err := client.ListByResourceGroupSender(req)
   417  	if err != nil {
   418  		result.Response = autorest.Response{Response: resp}
   419  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "ListByResourceGroup", resp, "Failure sending request")
   420  		return
   421  	}
   422  
   423  	result, err = client.ListByResourceGroupResponder(resp)
   424  	if err != nil {
   425  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "ListByResourceGroup", resp, "Failure responding to request")
   426  		return
   427  	}
   428  
   429  	return
   430  }
   431  
   432  // ListByResourceGroupPreparer prepares the ListByResourceGroup request.
   433  func (client ActionGroupsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
   434  	pathParameters := map[string]interface{}{
   435  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   436  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   437  	}
   438  
   439  	const APIVersion = "2019-06-01"
   440  	queryParameters := map[string]interface{}{
   441  		"api-version": APIVersion,
   442  	}
   443  
   444  	preparer := autorest.CreatePreparer(
   445  		autorest.AsGet(),
   446  		autorest.WithBaseURL(client.BaseURI),
   447  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/actionGroups", pathParameters),
   448  		autorest.WithQueryParameters(queryParameters))
   449  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   450  }
   451  
   452  // ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
   453  // http.Response Body if it receives an error.
   454  func (client ActionGroupsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
   455  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   456  }
   457  
   458  // ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
   459  // closes the http.Response Body.
   460  func (client ActionGroupsClient) ListByResourceGroupResponder(resp *http.Response) (result ActionGroupList, err error) {
   461  	err = autorest.Respond(
   462  		resp,
   463  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   464  		autorest.ByUnmarshallingJSON(&result),
   465  		autorest.ByClosing())
   466  	result.Response = autorest.Response{Response: resp}
   467  	return
   468  }
   469  
   470  // ListBySubscriptionID get a list of all action groups in a subscription.
   471  func (client ActionGroupsClient) ListBySubscriptionID(ctx context.Context) (result ActionGroupList, err error) {
   472  	if tracing.IsEnabled() {
   473  		ctx = tracing.StartSpan(ctx, fqdn+"/ActionGroupsClient.ListBySubscriptionID")
   474  		defer func() {
   475  			sc := -1
   476  			if result.Response.Response != nil {
   477  				sc = result.Response.Response.StatusCode
   478  			}
   479  			tracing.EndSpan(ctx, sc, err)
   480  		}()
   481  	}
   482  	if err := validation.Validate([]validation.Validation{
   483  		{TargetValue: client.SubscriptionID,
   484  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   485  		return result, validation.NewError("insights.ActionGroupsClient", "ListBySubscriptionID", err.Error())
   486  	}
   487  
   488  	req, err := client.ListBySubscriptionIDPreparer(ctx)
   489  	if err != nil {
   490  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "ListBySubscriptionID", nil, "Failure preparing request")
   491  		return
   492  	}
   493  
   494  	resp, err := client.ListBySubscriptionIDSender(req)
   495  	if err != nil {
   496  		result.Response = autorest.Response{Response: resp}
   497  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "ListBySubscriptionID", resp, "Failure sending request")
   498  		return
   499  	}
   500  
   501  	result, err = client.ListBySubscriptionIDResponder(resp)
   502  	if err != nil {
   503  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "ListBySubscriptionID", resp, "Failure responding to request")
   504  		return
   505  	}
   506  
   507  	return
   508  }
   509  
   510  // ListBySubscriptionIDPreparer prepares the ListBySubscriptionID request.
   511  func (client ActionGroupsClient) ListBySubscriptionIDPreparer(ctx context.Context) (*http.Request, error) {
   512  	pathParameters := map[string]interface{}{
   513  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   514  	}
   515  
   516  	const APIVersion = "2019-06-01"
   517  	queryParameters := map[string]interface{}{
   518  		"api-version": APIVersion,
   519  	}
   520  
   521  	preparer := autorest.CreatePreparer(
   522  		autorest.AsGet(),
   523  		autorest.WithBaseURL(client.BaseURI),
   524  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/actionGroups", pathParameters),
   525  		autorest.WithQueryParameters(queryParameters))
   526  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   527  }
   528  
   529  // ListBySubscriptionIDSender sends the ListBySubscriptionID request. The method will close the
   530  // http.Response Body if it receives an error.
   531  func (client ActionGroupsClient) ListBySubscriptionIDSender(req *http.Request) (*http.Response, error) {
   532  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   533  }
   534  
   535  // ListBySubscriptionIDResponder handles the response to the ListBySubscriptionID request. The method always
   536  // closes the http.Response Body.
   537  func (client ActionGroupsClient) ListBySubscriptionIDResponder(resp *http.Response) (result ActionGroupList, err error) {
   538  	err = autorest.Respond(
   539  		resp,
   540  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   541  		autorest.ByUnmarshallingJSON(&result),
   542  		autorest.ByClosing())
   543  	result.Response = autorest.Response{Response: resp}
   544  	return
   545  }
   546  
   547  // Update updates an existing action group's tags. To update other fields use the CreateOrUpdate method.
   548  // Parameters:
   549  // resourceGroupName - the name of the resource group. The name is case insensitive.
   550  // actionGroupName - the name of the action group.
   551  // actionGroupPatch - parameters supplied to the operation.
   552  func (client ActionGroupsClient) Update(ctx context.Context, resourceGroupName string, actionGroupName string, actionGroupPatch ActionGroupPatchBody) (result ActionGroupResource, err error) {
   553  	if tracing.IsEnabled() {
   554  		ctx = tracing.StartSpan(ctx, fqdn+"/ActionGroupsClient.Update")
   555  		defer func() {
   556  			sc := -1
   557  			if result.Response.Response != nil {
   558  				sc = result.Response.Response.StatusCode
   559  			}
   560  			tracing.EndSpan(ctx, sc, err)
   561  		}()
   562  	}
   563  	if err := validation.Validate([]validation.Validation{
   564  		{TargetValue: client.SubscriptionID,
   565  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   566  		{TargetValue: resourceGroupName,
   567  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   568  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   569  		return result, validation.NewError("insights.ActionGroupsClient", "Update", err.Error())
   570  	}
   571  
   572  	req, err := client.UpdatePreparer(ctx, resourceGroupName, actionGroupName, actionGroupPatch)
   573  	if err != nil {
   574  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "Update", nil, "Failure preparing request")
   575  		return
   576  	}
   577  
   578  	resp, err := client.UpdateSender(req)
   579  	if err != nil {
   580  		result.Response = autorest.Response{Response: resp}
   581  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "Update", resp, "Failure sending request")
   582  		return
   583  	}
   584  
   585  	result, err = client.UpdateResponder(resp)
   586  	if err != nil {
   587  		err = autorest.NewErrorWithError(err, "insights.ActionGroupsClient", "Update", resp, "Failure responding to request")
   588  		return
   589  	}
   590  
   591  	return
   592  }
   593  
   594  // UpdatePreparer prepares the Update request.
   595  func (client ActionGroupsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, actionGroupName string, actionGroupPatch ActionGroupPatchBody) (*http.Request, error) {
   596  	pathParameters := map[string]interface{}{
   597  		"actionGroupName":   autorest.Encode("path", actionGroupName),
   598  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   599  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   600  	}
   601  
   602  	const APIVersion = "2019-06-01"
   603  	queryParameters := map[string]interface{}{
   604  		"api-version": APIVersion,
   605  	}
   606  
   607  	preparer := autorest.CreatePreparer(
   608  		autorest.AsContentType("application/json; charset=utf-8"),
   609  		autorest.AsPatch(),
   610  		autorest.WithBaseURL(client.BaseURI),
   611  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/actionGroups/{actionGroupName}", pathParameters),
   612  		autorest.WithJSON(actionGroupPatch),
   613  		autorest.WithQueryParameters(queryParameters))
   614  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   615  }
   616  
   617  // UpdateSender sends the Update request. The method will close the
   618  // http.Response Body if it receives an error.
   619  func (client ActionGroupsClient) UpdateSender(req *http.Request) (*http.Response, error) {
   620  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   621  }
   622  
   623  // UpdateResponder handles the response to the Update request. The method always
   624  // closes the http.Response Body.
   625  func (client ActionGroupsClient) UpdateResponder(resp *http.Response) (result ActionGroupResource, err error) {
   626  	err = autorest.Respond(
   627  		resp,
   628  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   629  		autorest.ByUnmarshallingJSON(&result),
   630  		autorest.ByClosing())
   631  	result.Response = autorest.Response{Response: resp}
   632  	return
   633  }
   634  

View as plain text