...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-05-01-preview/diagnostics/managementgroupdiagnosticsettings.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2021-05-01-preview/diagnostics

     1  package diagnostics
     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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // ManagementGroupDiagnosticSettingsClient is the monitor Management Client
    18  type ManagementGroupDiagnosticSettingsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewManagementGroupDiagnosticSettingsClient creates an instance of the ManagementGroupDiagnosticSettingsClient
    23  // client.
    24  func NewManagementGroupDiagnosticSettingsClient(subscriptionID string) ManagementGroupDiagnosticSettingsClient {
    25  	return NewManagementGroupDiagnosticSettingsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewManagementGroupDiagnosticSettingsClientWithBaseURI creates an instance of the
    29  // ManagementGroupDiagnosticSettingsClient client using a custom endpoint.  Use this when interacting with an Azure
    30  // cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    31  func NewManagementGroupDiagnosticSettingsClientWithBaseURI(baseURI string, subscriptionID string) ManagementGroupDiagnosticSettingsClient {
    32  	return ManagementGroupDiagnosticSettingsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // CreateOrUpdate creates or updates management group diagnostic settings for the specified resource.
    36  // Parameters:
    37  // managementGroupID - the management group id.
    38  // parameters - parameters supplied to the operation.
    39  // name - the name of the diagnostic setting.
    40  func (client ManagementGroupDiagnosticSettingsClient) CreateOrUpdate(ctx context.Context, managementGroupID string, parameters ManagementGroupDiagnosticSettingsResource, name string) (result ManagementGroupDiagnosticSettingsResource, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/ManagementGroupDiagnosticSettingsClient.CreateOrUpdate")
    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  	req, err := client.CreateOrUpdatePreparer(ctx, managementGroupID, parameters, name)
    52  	if err != nil {
    53  		err = autorest.NewErrorWithError(err, "diagnostics.ManagementGroupDiagnosticSettingsClient", "CreateOrUpdate", nil, "Failure preparing request")
    54  		return
    55  	}
    56  
    57  	resp, err := client.CreateOrUpdateSender(req)
    58  	if err != nil {
    59  		result.Response = autorest.Response{Response: resp}
    60  		err = autorest.NewErrorWithError(err, "diagnostics.ManagementGroupDiagnosticSettingsClient", "CreateOrUpdate", resp, "Failure sending request")
    61  		return
    62  	}
    63  
    64  	result, err = client.CreateOrUpdateResponder(resp)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "diagnostics.ManagementGroupDiagnosticSettingsClient", "CreateOrUpdate", resp, "Failure responding to request")
    67  		return
    68  	}
    69  
    70  	return
    71  }
    72  
    73  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    74  func (client ManagementGroupDiagnosticSettingsClient) CreateOrUpdatePreparer(ctx context.Context, managementGroupID string, parameters ManagementGroupDiagnosticSettingsResource, name string) (*http.Request, error) {
    75  	pathParameters := map[string]interface{}{
    76  		"managementGroupId": managementGroupID,
    77  		"name":              autorest.Encode("path", name),
    78  	}
    79  
    80  	const APIVersion = "2021-05-01-preview"
    81  	queryParameters := map[string]interface{}{
    82  		"api-version": APIVersion,
    83  	}
    84  
    85  	parameters.SystemData = nil
    86  	preparer := autorest.CreatePreparer(
    87  		autorest.AsContentType("application/json; charset=utf-8"),
    88  		autorest.AsPut(),
    89  		autorest.WithBaseURL(client.BaseURI),
    90  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Insights/diagnosticSettings/{name}", pathParameters),
    91  		autorest.WithJSON(parameters),
    92  		autorest.WithQueryParameters(queryParameters))
    93  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    94  }
    95  
    96  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
    97  // http.Response Body if it receives an error.
    98  func (client ManagementGroupDiagnosticSettingsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
    99  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   100  }
   101  
   102  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   103  // closes the http.Response Body.
   104  func (client ManagementGroupDiagnosticSettingsClient) CreateOrUpdateResponder(resp *http.Response) (result ManagementGroupDiagnosticSettingsResource, err error) {
   105  	err = autorest.Respond(
   106  		resp,
   107  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   108  		autorest.ByUnmarshallingJSON(&result),
   109  		autorest.ByClosing())
   110  	result.Response = autorest.Response{Response: resp}
   111  	return
   112  }
   113  
   114  // Delete deletes existing management group diagnostic settings for the specified resource.
   115  // Parameters:
   116  // managementGroupID - the management group id.
   117  // name - the name of the diagnostic setting.
   118  func (client ManagementGroupDiagnosticSettingsClient) Delete(ctx context.Context, managementGroupID string, name string) (result autorest.Response, err error) {
   119  	if tracing.IsEnabled() {
   120  		ctx = tracing.StartSpan(ctx, fqdn+"/ManagementGroupDiagnosticSettingsClient.Delete")
   121  		defer func() {
   122  			sc := -1
   123  			if result.Response != nil {
   124  				sc = result.Response.StatusCode
   125  			}
   126  			tracing.EndSpan(ctx, sc, err)
   127  		}()
   128  	}
   129  	req, err := client.DeletePreparer(ctx, managementGroupID, name)
   130  	if err != nil {
   131  		err = autorest.NewErrorWithError(err, "diagnostics.ManagementGroupDiagnosticSettingsClient", "Delete", nil, "Failure preparing request")
   132  		return
   133  	}
   134  
   135  	resp, err := client.DeleteSender(req)
   136  	if err != nil {
   137  		result.Response = resp
   138  		err = autorest.NewErrorWithError(err, "diagnostics.ManagementGroupDiagnosticSettingsClient", "Delete", resp, "Failure sending request")
   139  		return
   140  	}
   141  
   142  	result, err = client.DeleteResponder(resp)
   143  	if err != nil {
   144  		err = autorest.NewErrorWithError(err, "diagnostics.ManagementGroupDiagnosticSettingsClient", "Delete", resp, "Failure responding to request")
   145  		return
   146  	}
   147  
   148  	return
   149  }
   150  
   151  // DeletePreparer prepares the Delete request.
   152  func (client ManagementGroupDiagnosticSettingsClient) DeletePreparer(ctx context.Context, managementGroupID string, name string) (*http.Request, error) {
   153  	pathParameters := map[string]interface{}{
   154  		"managementGroupId": managementGroupID,
   155  		"name":              autorest.Encode("path", name),
   156  	}
   157  
   158  	const APIVersion = "2021-05-01-preview"
   159  	queryParameters := map[string]interface{}{
   160  		"api-version": APIVersion,
   161  	}
   162  
   163  	preparer := autorest.CreatePreparer(
   164  		autorest.AsDelete(),
   165  		autorest.WithBaseURL(client.BaseURI),
   166  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Insights/diagnosticSettings/{name}", pathParameters),
   167  		autorest.WithQueryParameters(queryParameters))
   168  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   169  }
   170  
   171  // DeleteSender sends the Delete request. The method will close the
   172  // http.Response Body if it receives an error.
   173  func (client ManagementGroupDiagnosticSettingsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   174  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   175  }
   176  
   177  // DeleteResponder handles the response to the Delete request. The method always
   178  // closes the http.Response Body.
   179  func (client ManagementGroupDiagnosticSettingsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   180  	err = autorest.Respond(
   181  		resp,
   182  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   183  		autorest.ByClosing())
   184  	result.Response = resp
   185  	return
   186  }
   187  
   188  // Get gets the active management group diagnostic settings for the specified resource.
   189  // Parameters:
   190  // managementGroupID - the management group id.
   191  // name - the name of the diagnostic setting.
   192  func (client ManagementGroupDiagnosticSettingsClient) Get(ctx context.Context, managementGroupID string, name string) (result ManagementGroupDiagnosticSettingsResource, err error) {
   193  	if tracing.IsEnabled() {
   194  		ctx = tracing.StartSpan(ctx, fqdn+"/ManagementGroupDiagnosticSettingsClient.Get")
   195  		defer func() {
   196  			sc := -1
   197  			if result.Response.Response != nil {
   198  				sc = result.Response.Response.StatusCode
   199  			}
   200  			tracing.EndSpan(ctx, sc, err)
   201  		}()
   202  	}
   203  	req, err := client.GetPreparer(ctx, managementGroupID, name)
   204  	if err != nil {
   205  		err = autorest.NewErrorWithError(err, "diagnostics.ManagementGroupDiagnosticSettingsClient", "Get", nil, "Failure preparing request")
   206  		return
   207  	}
   208  
   209  	resp, err := client.GetSender(req)
   210  	if err != nil {
   211  		result.Response = autorest.Response{Response: resp}
   212  		err = autorest.NewErrorWithError(err, "diagnostics.ManagementGroupDiagnosticSettingsClient", "Get", resp, "Failure sending request")
   213  		return
   214  	}
   215  
   216  	result, err = client.GetResponder(resp)
   217  	if err != nil {
   218  		err = autorest.NewErrorWithError(err, "diagnostics.ManagementGroupDiagnosticSettingsClient", "Get", resp, "Failure responding to request")
   219  		return
   220  	}
   221  
   222  	return
   223  }
   224  
   225  // GetPreparer prepares the Get request.
   226  func (client ManagementGroupDiagnosticSettingsClient) GetPreparer(ctx context.Context, managementGroupID string, name string) (*http.Request, error) {
   227  	pathParameters := map[string]interface{}{
   228  		"managementGroupId": managementGroupID,
   229  		"name":              autorest.Encode("path", name),
   230  	}
   231  
   232  	const APIVersion = "2021-05-01-preview"
   233  	queryParameters := map[string]interface{}{
   234  		"api-version": APIVersion,
   235  	}
   236  
   237  	preparer := autorest.CreatePreparer(
   238  		autorest.AsGet(),
   239  		autorest.WithBaseURL(client.BaseURI),
   240  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Insights/diagnosticSettings/{name}", pathParameters),
   241  		autorest.WithQueryParameters(queryParameters))
   242  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   243  }
   244  
   245  // GetSender sends the Get request. The method will close the
   246  // http.Response Body if it receives an error.
   247  func (client ManagementGroupDiagnosticSettingsClient) GetSender(req *http.Request) (*http.Response, error) {
   248  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   249  }
   250  
   251  // GetResponder handles the response to the Get request. The method always
   252  // closes the http.Response Body.
   253  func (client ManagementGroupDiagnosticSettingsClient) GetResponder(resp *http.Response) (result ManagementGroupDiagnosticSettingsResource, err error) {
   254  	err = autorest.Respond(
   255  		resp,
   256  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   257  		autorest.ByUnmarshallingJSON(&result),
   258  		autorest.ByClosing())
   259  	result.Response = autorest.Response{Response: resp}
   260  	return
   261  }
   262  
   263  // List gets the active management group diagnostic settings list for the specified management group.
   264  // Parameters:
   265  // managementGroupID - the management group id.
   266  func (client ManagementGroupDiagnosticSettingsClient) List(ctx context.Context, managementGroupID string) (result ManagementGroupDiagnosticSettingsResourceCollection, err error) {
   267  	if tracing.IsEnabled() {
   268  		ctx = tracing.StartSpan(ctx, fqdn+"/ManagementGroupDiagnosticSettingsClient.List")
   269  		defer func() {
   270  			sc := -1
   271  			if result.Response.Response != nil {
   272  				sc = result.Response.Response.StatusCode
   273  			}
   274  			tracing.EndSpan(ctx, sc, err)
   275  		}()
   276  	}
   277  	req, err := client.ListPreparer(ctx, managementGroupID)
   278  	if err != nil {
   279  		err = autorest.NewErrorWithError(err, "diagnostics.ManagementGroupDiagnosticSettingsClient", "List", nil, "Failure preparing request")
   280  		return
   281  	}
   282  
   283  	resp, err := client.ListSender(req)
   284  	if err != nil {
   285  		result.Response = autorest.Response{Response: resp}
   286  		err = autorest.NewErrorWithError(err, "diagnostics.ManagementGroupDiagnosticSettingsClient", "List", resp, "Failure sending request")
   287  		return
   288  	}
   289  
   290  	result, err = client.ListResponder(resp)
   291  	if err != nil {
   292  		err = autorest.NewErrorWithError(err, "diagnostics.ManagementGroupDiagnosticSettingsClient", "List", resp, "Failure responding to request")
   293  		return
   294  	}
   295  
   296  	return
   297  }
   298  
   299  // ListPreparer prepares the List request.
   300  func (client ManagementGroupDiagnosticSettingsClient) ListPreparer(ctx context.Context, managementGroupID string) (*http.Request, error) {
   301  	pathParameters := map[string]interface{}{
   302  		"managementGroupId": managementGroupID,
   303  	}
   304  
   305  	const APIVersion = "2021-05-01-preview"
   306  	queryParameters := map[string]interface{}{
   307  		"api-version": APIVersion,
   308  	}
   309  
   310  	preparer := autorest.CreatePreparer(
   311  		autorest.AsGet(),
   312  		autorest.WithBaseURL(client.BaseURI),
   313  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Insights/diagnosticSettings", pathParameters),
   314  		autorest.WithQueryParameters(queryParameters))
   315  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   316  }
   317  
   318  // ListSender sends the List request. The method will close the
   319  // http.Response Body if it receives an error.
   320  func (client ManagementGroupDiagnosticSettingsClient) ListSender(req *http.Request) (*http.Response, error) {
   321  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   322  }
   323  
   324  // ListResponder handles the response to the List request. The method always
   325  // closes the http.Response Body.
   326  func (client ManagementGroupDiagnosticSettingsClient) ListResponder(resp *http.Response) (result ManagementGroupDiagnosticSettingsResourceCollection, err error) {
   327  	err = autorest.Respond(
   328  		resp,
   329  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   330  		autorest.ByUnmarshallingJSON(&result),
   331  		autorest.ByClosing())
   332  	result.Response = autorest.Response{Response: resp}
   333  	return
   334  }
   335  

View as plain text