1package operationalinsights 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// DataSourcesClient is the operational Insights Client 30type DataSourcesClient struct { 31 BaseClient 32} 33 34// NewDataSourcesClient creates an instance of the DataSourcesClient client. 35func NewDataSourcesClient(subscriptionID string) DataSourcesClient { 36 return NewDataSourcesClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewDataSourcesClientWithBaseURI creates an instance of the DataSourcesClient client. 40func NewDataSourcesClientWithBaseURI(baseURI string, subscriptionID string) DataSourcesClient { 41 return DataSourcesClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// CreateOrUpdate create or update a data source. 45// Parameters: 46// resourceGroupName - the name of the resource group to get. The name is case insensitive. 47// workspaceName - name of the Log Analytics Workspace that will contain the datasource 48// dataSourceName - the name of the datasource resource. 49// parameters - the parameters required to create or update a datasource. 50func (client DataSourcesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, workspaceName string, dataSourceName string, parameters DataSource) (result DataSource, err error) { 51 if tracing.IsEnabled() { 52 ctx = tracing.StartSpan(ctx, fqdn+"/DataSourcesClient.CreateOrUpdate") 53 defer func() { 54 sc := -1 55 if result.Response.Response != nil { 56 sc = result.Response.Response.StatusCode 57 } 58 tracing.EndSpan(ctx, sc, err) 59 }() 60 } 61 if err := validation.Validate([]validation.Validation{ 62 {TargetValue: resourceGroupName, 63 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 64 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 65 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 66 {TargetValue: parameters, 67 Constraints: []validation.Constraint{{Target: "parameters.Properties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 68 return result, validation.NewError("operationalinsights.DataSourcesClient", "CreateOrUpdate", err.Error()) 69 } 70 71 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, workspaceName, dataSourceName, parameters) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "CreateOrUpdate", nil, "Failure preparing request") 74 return 75 } 76 77 resp, err := client.CreateOrUpdateSender(req) 78 if err != nil { 79 result.Response = autorest.Response{Response: resp} 80 err = autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "CreateOrUpdate", resp, "Failure sending request") 81 return 82 } 83 84 result, err = client.CreateOrUpdateResponder(resp) 85 if err != nil { 86 err = autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "CreateOrUpdate", resp, "Failure responding to request") 87 } 88 89 return 90} 91 92// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 93func (client DataSourcesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, workspaceName string, dataSourceName string, parameters DataSource) (*http.Request, error) { 94 pathParameters := map[string]interface{}{ 95 "dataSourceName": autorest.Encode("path", dataSourceName), 96 "resourceGroupName": autorest.Encode("path", resourceGroupName), 97 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 98 "workspaceName": autorest.Encode("path", workspaceName), 99 } 100 101 const APIVersion = "2015-11-01-preview" 102 queryParameters := map[string]interface{}{ 103 "api-version": APIVersion, 104 } 105 106 preparer := autorest.CreatePreparer( 107 autorest.AsContentType("application/json; charset=utf-8"), 108 autorest.AsPut(), 109 autorest.WithBaseURL(client.BaseURI), 110 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/dataSources/{dataSourceName}", pathParameters), 111 autorest.WithJSON(parameters), 112 autorest.WithQueryParameters(queryParameters)) 113 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 114} 115 116// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 117// http.Response Body if it receives an error. 118func (client DataSourcesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 119 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 120 return autorest.SendWithSender(client, req, sd...) 121} 122 123// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 124// closes the http.Response Body. 125func (client DataSourcesClient) CreateOrUpdateResponder(resp *http.Response) (result DataSource, err error) { 126 err = autorest.Respond( 127 resp, 128 client.ByInspecting(), 129 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 130 autorest.ByUnmarshallingJSON(&result), 131 autorest.ByClosing()) 132 result.Response = autorest.Response{Response: resp} 133 return 134} 135 136// Delete deletes a data source instance. 137// Parameters: 138// resourceGroupName - the name of the resource group to get. The name is case insensitive. 139// workspaceName - name of the Log Analytics Workspace that contains the datasource. 140// dataSourceName - name of the datasource. 141func (client DataSourcesClient) Delete(ctx context.Context, resourceGroupName string, workspaceName string, dataSourceName string) (result autorest.Response, err error) { 142 if tracing.IsEnabled() { 143 ctx = tracing.StartSpan(ctx, fqdn+"/DataSourcesClient.Delete") 144 defer func() { 145 sc := -1 146 if result.Response != nil { 147 sc = result.Response.StatusCode 148 } 149 tracing.EndSpan(ctx, sc, err) 150 }() 151 } 152 if err := validation.Validate([]validation.Validation{ 153 {TargetValue: resourceGroupName, 154 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 155 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 156 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 157 return result, validation.NewError("operationalinsights.DataSourcesClient", "Delete", err.Error()) 158 } 159 160 req, err := client.DeletePreparer(ctx, resourceGroupName, workspaceName, dataSourceName) 161 if err != nil { 162 err = autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "Delete", nil, "Failure preparing request") 163 return 164 } 165 166 resp, err := client.DeleteSender(req) 167 if err != nil { 168 result.Response = resp 169 err = autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "Delete", resp, "Failure sending request") 170 return 171 } 172 173 result, err = client.DeleteResponder(resp) 174 if err != nil { 175 err = autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "Delete", resp, "Failure responding to request") 176 } 177 178 return 179} 180 181// DeletePreparer prepares the Delete request. 182func (client DataSourcesClient) DeletePreparer(ctx context.Context, resourceGroupName string, workspaceName string, dataSourceName string) (*http.Request, error) { 183 pathParameters := map[string]interface{}{ 184 "dataSourceName": autorest.Encode("path", dataSourceName), 185 "resourceGroupName": autorest.Encode("path", resourceGroupName), 186 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 187 "workspaceName": autorest.Encode("path", workspaceName), 188 } 189 190 const APIVersion = "2015-11-01-preview" 191 queryParameters := map[string]interface{}{ 192 "api-version": APIVersion, 193 } 194 195 preparer := autorest.CreatePreparer( 196 autorest.AsDelete(), 197 autorest.WithBaseURL(client.BaseURI), 198 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/dataSources/{dataSourceName}", pathParameters), 199 autorest.WithQueryParameters(queryParameters)) 200 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 201} 202 203// DeleteSender sends the Delete request. The method will close the 204// http.Response Body if it receives an error. 205func (client DataSourcesClient) DeleteSender(req *http.Request) (*http.Response, error) { 206 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 207 return autorest.SendWithSender(client, req, sd...) 208} 209 210// DeleteResponder handles the response to the Delete request. The method always 211// closes the http.Response Body. 212func (client DataSourcesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 213 err = autorest.Respond( 214 resp, 215 client.ByInspecting(), 216 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 217 autorest.ByClosing()) 218 result.Response = resp 219 return 220} 221 222// Get gets a datasource instance. 223// Parameters: 224// resourceGroupName - the name of the resource group to get. The name is case insensitive. 225// workspaceName - name of the Log Analytics Workspace that contains the datasource. 226// dataSourceName - name of the datasource 227func (client DataSourcesClient) Get(ctx context.Context, resourceGroupName string, workspaceName string, dataSourceName string) (result DataSource, err error) { 228 if tracing.IsEnabled() { 229 ctx = tracing.StartSpan(ctx, fqdn+"/DataSourcesClient.Get") 230 defer func() { 231 sc := -1 232 if result.Response.Response != nil { 233 sc = result.Response.Response.StatusCode 234 } 235 tracing.EndSpan(ctx, sc, err) 236 }() 237 } 238 if err := validation.Validate([]validation.Validation{ 239 {TargetValue: resourceGroupName, 240 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 241 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 242 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 243 return result, validation.NewError("operationalinsights.DataSourcesClient", "Get", err.Error()) 244 } 245 246 req, err := client.GetPreparer(ctx, resourceGroupName, workspaceName, dataSourceName) 247 if err != nil { 248 err = autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "Get", nil, "Failure preparing request") 249 return 250 } 251 252 resp, err := client.GetSender(req) 253 if err != nil { 254 result.Response = autorest.Response{Response: resp} 255 err = autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "Get", resp, "Failure sending request") 256 return 257 } 258 259 result, err = client.GetResponder(resp) 260 if err != nil { 261 err = autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "Get", resp, "Failure responding to request") 262 } 263 264 return 265} 266 267// GetPreparer prepares the Get request. 268func (client DataSourcesClient) GetPreparer(ctx context.Context, resourceGroupName string, workspaceName string, dataSourceName string) (*http.Request, error) { 269 pathParameters := map[string]interface{}{ 270 "dataSourceName": autorest.Encode("path", dataSourceName), 271 "resourceGroupName": autorest.Encode("path", resourceGroupName), 272 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 273 "workspaceName": autorest.Encode("path", workspaceName), 274 } 275 276 const APIVersion = "2015-11-01-preview" 277 queryParameters := map[string]interface{}{ 278 "api-version": APIVersion, 279 } 280 281 preparer := autorest.CreatePreparer( 282 autorest.AsGet(), 283 autorest.WithBaseURL(client.BaseURI), 284 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/dataSources/{dataSourceName}", pathParameters), 285 autorest.WithQueryParameters(queryParameters)) 286 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 287} 288 289// GetSender sends the Get request. The method will close the 290// http.Response Body if it receives an error. 291func (client DataSourcesClient) GetSender(req *http.Request) (*http.Response, error) { 292 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 293 return autorest.SendWithSender(client, req, sd...) 294} 295 296// GetResponder handles the response to the Get request. The method always 297// closes the http.Response Body. 298func (client DataSourcesClient) GetResponder(resp *http.Response) (result DataSource, err error) { 299 err = autorest.Respond( 300 resp, 301 client.ByInspecting(), 302 azure.WithErrorUnlessStatusCode(http.StatusOK), 303 autorest.ByUnmarshallingJSON(&result), 304 autorest.ByClosing()) 305 result.Response = autorest.Response{Response: resp} 306 return 307} 308 309// ListByWorkspace gets the first page of data source instances in a workspace with the link to the next page. 310// Parameters: 311// resourceGroupName - the name of the resource group to get. The name is case insensitive. 312// workspaceName - the workspace that contains the data sources. 313// filter - the filter to apply on the operation. 314// skiptoken - starting point of the collection of data source instances. 315func (client DataSourcesClient) ListByWorkspace(ctx context.Context, resourceGroupName string, workspaceName string, filter string, skiptoken string) (result DataSourceListResultPage, err error) { 316 if tracing.IsEnabled() { 317 ctx = tracing.StartSpan(ctx, fqdn+"/DataSourcesClient.ListByWorkspace") 318 defer func() { 319 sc := -1 320 if result.dslr.Response.Response != nil { 321 sc = result.dslr.Response.Response.StatusCode 322 } 323 tracing.EndSpan(ctx, sc, err) 324 }() 325 } 326 if err := validation.Validate([]validation.Validation{ 327 {TargetValue: resourceGroupName, 328 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 329 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 330 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 331 return result, validation.NewError("operationalinsights.DataSourcesClient", "ListByWorkspace", err.Error()) 332 } 333 334 result.fn = client.listByWorkspaceNextResults 335 req, err := client.ListByWorkspacePreparer(ctx, resourceGroupName, workspaceName, filter, skiptoken) 336 if err != nil { 337 err = autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "ListByWorkspace", nil, "Failure preparing request") 338 return 339 } 340 341 resp, err := client.ListByWorkspaceSender(req) 342 if err != nil { 343 result.dslr.Response = autorest.Response{Response: resp} 344 err = autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "ListByWorkspace", resp, "Failure sending request") 345 return 346 } 347 348 result.dslr, err = client.ListByWorkspaceResponder(resp) 349 if err != nil { 350 err = autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "ListByWorkspace", resp, "Failure responding to request") 351 } 352 353 return 354} 355 356// ListByWorkspacePreparer prepares the ListByWorkspace request. 357func (client DataSourcesClient) ListByWorkspacePreparer(ctx context.Context, resourceGroupName string, workspaceName string, filter string, skiptoken string) (*http.Request, error) { 358 pathParameters := map[string]interface{}{ 359 "resourceGroupName": autorest.Encode("path", resourceGroupName), 360 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 361 "workspaceName": autorest.Encode("path", workspaceName), 362 } 363 364 const APIVersion = "2015-11-01-preview" 365 queryParameters := map[string]interface{}{ 366 "$filter": autorest.Encode("query", filter), 367 "api-version": APIVersion, 368 } 369 if len(skiptoken) > 0 { 370 queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) 371 } 372 373 preparer := autorest.CreatePreparer( 374 autorest.AsGet(), 375 autorest.WithBaseURL(client.BaseURI), 376 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/dataSources", pathParameters), 377 autorest.WithQueryParameters(queryParameters)) 378 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 379} 380 381// ListByWorkspaceSender sends the ListByWorkspace request. The method will close the 382// http.Response Body if it receives an error. 383func (client DataSourcesClient) ListByWorkspaceSender(req *http.Request) (*http.Response, error) { 384 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 385 return autorest.SendWithSender(client, req, sd...) 386} 387 388// ListByWorkspaceResponder handles the response to the ListByWorkspace request. The method always 389// closes the http.Response Body. 390func (client DataSourcesClient) ListByWorkspaceResponder(resp *http.Response) (result DataSourceListResult, err error) { 391 err = autorest.Respond( 392 resp, 393 client.ByInspecting(), 394 azure.WithErrorUnlessStatusCode(http.StatusOK), 395 autorest.ByUnmarshallingJSON(&result), 396 autorest.ByClosing()) 397 result.Response = autorest.Response{Response: resp} 398 return 399} 400 401// listByWorkspaceNextResults retrieves the next set of results, if any. 402func (client DataSourcesClient) listByWorkspaceNextResults(ctx context.Context, lastResults DataSourceListResult) (result DataSourceListResult, err error) { 403 req, err := lastResults.dataSourceListResultPreparer(ctx) 404 if err != nil { 405 return result, autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "listByWorkspaceNextResults", nil, "Failure preparing next results request") 406 } 407 if req == nil { 408 return 409 } 410 resp, err := client.ListByWorkspaceSender(req) 411 if err != nil { 412 result.Response = autorest.Response{Response: resp} 413 return result, autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "listByWorkspaceNextResults", resp, "Failure sending next results request") 414 } 415 result, err = client.ListByWorkspaceResponder(resp) 416 if err != nil { 417 err = autorest.NewErrorWithError(err, "operationalinsights.DataSourcesClient", "listByWorkspaceNextResults", resp, "Failure responding to next results request") 418 } 419 return 420} 421 422// ListByWorkspaceComplete enumerates all values, automatically crossing page boundaries as required. 423func (client DataSourcesClient) ListByWorkspaceComplete(ctx context.Context, resourceGroupName string, workspaceName string, filter string, skiptoken string) (result DataSourceListResultIterator, err error) { 424 if tracing.IsEnabled() { 425 ctx = tracing.StartSpan(ctx, fqdn+"/DataSourcesClient.ListByWorkspace") 426 defer func() { 427 sc := -1 428 if result.Response().Response.Response != nil { 429 sc = result.page.Response().Response.Response.StatusCode 430 } 431 tracing.EndSpan(ctx, sc, err) 432 }() 433 } 434 result.page, err = client.ListByWorkspace(ctx, resourceGroupName, workspaceName, filter, skiptoken) 435 return 436} 437