...

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

View as plain text