...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2018-03-01/insights/diagnosticsettings.go

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

View as plain text