1package timeseriesinsights 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// EventSourcesClient is the time Series Insights client 30type EventSourcesClient struct { 31 BaseClient 32} 33 34// NewEventSourcesClient creates an instance of the EventSourcesClient client. 35func NewEventSourcesClient(subscriptionID string) EventSourcesClient { 36 return NewEventSourcesClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewEventSourcesClientWithBaseURI creates an instance of the EventSourcesClient client using a custom endpoint. Use 40// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewEventSourcesClientWithBaseURI(baseURI string, subscriptionID string) EventSourcesClient { 42 return EventSourcesClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// CreateOrUpdate create or update an event source under the specified environment. 46// Parameters: 47// resourceGroupName - name of an Azure Resource group. 48// environmentName - the name of the Time Series Insights environment associated with the specified resource 49// group. 50// eventSourceName - name of the event source. 51// parameters - parameters for creating an event source resource. 52func (client EventSourcesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, environmentName string, eventSourceName string, parameters BasicEventSourceCreateOrUpdateParameters) (result EventSourceResourceModel, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/EventSourcesClient.CreateOrUpdate") 55 defer func() { 56 sc := -1 57 if result.Response.Response != nil { 58 sc = result.Response.Response.StatusCode 59 } 60 tracing.EndSpan(ctx, sc, err) 61 }() 62 } 63 if err := validation.Validate([]validation.Validation{ 64 {TargetValue: eventSourceName, 65 Constraints: []validation.Constraint{{Target: "eventSourceName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 66 {Target: "eventSourceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 67 {Target: "eventSourceName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 68 return result, validation.NewError("timeseriesinsights.EventSourcesClient", "CreateOrUpdate", err.Error()) 69 } 70 71 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, environmentName, eventSourceName, parameters) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "timeseriesinsights.EventSourcesClient", "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, "timeseriesinsights.EventSourcesClient", "CreateOrUpdate", resp, "Failure sending request") 81 return 82 } 83 84 result, err = client.CreateOrUpdateResponder(resp) 85 if err != nil { 86 err = autorest.NewErrorWithError(err, "timeseriesinsights.EventSourcesClient", "CreateOrUpdate", resp, "Failure responding to request") 87 } 88 89 return 90} 91 92// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 93func (client EventSourcesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, environmentName string, eventSourceName string, parameters BasicEventSourceCreateOrUpdateParameters) (*http.Request, error) { 94 pathParameters := map[string]interface{}{ 95 "environmentName": autorest.Encode("path", environmentName), 96 "eventSourceName": autorest.Encode("path", eventSourceName), 97 "resourceGroupName": autorest.Encode("path", resourceGroupName), 98 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 99 } 100 101 const APIVersion = "2017-02-28-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.TimeSeriesInsights/environments/{environmentName}/eventSources/{eventSourceName}", 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 EventSourcesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 119 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 120} 121 122// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 123// closes the http.Response Body. 124func (client EventSourcesClient) CreateOrUpdateResponder(resp *http.Response) (result EventSourceResourceModel, err error) { 125 err = autorest.Respond( 126 resp, 127 client.ByInspecting(), 128 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 129 autorest.ByUnmarshallingJSON(&result), 130 autorest.ByClosing()) 131 result.Response = autorest.Response{Response: resp} 132 return 133} 134 135// Delete deletes the event source with the specified name in the specified subscription, resource group, and 136// environment 137// Parameters: 138// resourceGroupName - name of an Azure Resource group. 139// environmentName - the name of the Time Series Insights environment associated with the specified resource 140// group. 141// eventSourceName - the name of the Time Series Insights event source associated with the specified 142// environment. 143func (client EventSourcesClient) Delete(ctx context.Context, resourceGroupName string, environmentName string, eventSourceName string) (result autorest.Response, err error) { 144 if tracing.IsEnabled() { 145 ctx = tracing.StartSpan(ctx, fqdn+"/EventSourcesClient.Delete") 146 defer func() { 147 sc := -1 148 if result.Response != nil { 149 sc = result.Response.StatusCode 150 } 151 tracing.EndSpan(ctx, sc, err) 152 }() 153 } 154 req, err := client.DeletePreparer(ctx, resourceGroupName, environmentName, eventSourceName) 155 if err != nil { 156 err = autorest.NewErrorWithError(err, "timeseriesinsights.EventSourcesClient", "Delete", nil, "Failure preparing request") 157 return 158 } 159 160 resp, err := client.DeleteSender(req) 161 if err != nil { 162 result.Response = resp 163 err = autorest.NewErrorWithError(err, "timeseriesinsights.EventSourcesClient", "Delete", resp, "Failure sending request") 164 return 165 } 166 167 result, err = client.DeleteResponder(resp) 168 if err != nil { 169 err = autorest.NewErrorWithError(err, "timeseriesinsights.EventSourcesClient", "Delete", resp, "Failure responding to request") 170 } 171 172 return 173} 174 175// DeletePreparer prepares the Delete request. 176func (client EventSourcesClient) DeletePreparer(ctx context.Context, resourceGroupName string, environmentName string, eventSourceName string) (*http.Request, error) { 177 pathParameters := map[string]interface{}{ 178 "environmentName": autorest.Encode("path", environmentName), 179 "eventSourceName": autorest.Encode("path", eventSourceName), 180 "resourceGroupName": autorest.Encode("path", resourceGroupName), 181 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 182 } 183 184 const APIVersion = "2017-02-28-preview" 185 queryParameters := map[string]interface{}{ 186 "api-version": APIVersion, 187 } 188 189 preparer := autorest.CreatePreparer( 190 autorest.AsDelete(), 191 autorest.WithBaseURL(client.BaseURI), 192 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.TimeSeriesInsights/environments/{environmentName}/eventSources/{eventSourceName}", pathParameters), 193 autorest.WithQueryParameters(queryParameters)) 194 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 195} 196 197// DeleteSender sends the Delete request. The method will close the 198// http.Response Body if it receives an error. 199func (client EventSourcesClient) DeleteSender(req *http.Request) (*http.Response, error) { 200 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 201} 202 203// DeleteResponder handles the response to the Delete request. The method always 204// closes the http.Response Body. 205func (client EventSourcesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 206 err = autorest.Respond( 207 resp, 208 client.ByInspecting(), 209 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 210 autorest.ByClosing()) 211 result.Response = resp 212 return 213} 214 215// Get gets the event source with the specified name in the specified environment. 216// Parameters: 217// resourceGroupName - name of an Azure Resource group. 218// environmentName - the name of the Time Series Insights environment associated with the specified resource 219// group. 220// eventSourceName - the name of the Time Series Insights event source associated with the specified 221// environment. 222func (client EventSourcesClient) Get(ctx context.Context, resourceGroupName string, environmentName string, eventSourceName string) (result EventSourceResourceModel, err error) { 223 if tracing.IsEnabled() { 224 ctx = tracing.StartSpan(ctx, fqdn+"/EventSourcesClient.Get") 225 defer func() { 226 sc := -1 227 if result.Response.Response != nil { 228 sc = result.Response.Response.StatusCode 229 } 230 tracing.EndSpan(ctx, sc, err) 231 }() 232 } 233 req, err := client.GetPreparer(ctx, resourceGroupName, environmentName, eventSourceName) 234 if err != nil { 235 err = autorest.NewErrorWithError(err, "timeseriesinsights.EventSourcesClient", "Get", nil, "Failure preparing request") 236 return 237 } 238 239 resp, err := client.GetSender(req) 240 if err != nil { 241 result.Response = autorest.Response{Response: resp} 242 err = autorest.NewErrorWithError(err, "timeseriesinsights.EventSourcesClient", "Get", resp, "Failure sending request") 243 return 244 } 245 246 result, err = client.GetResponder(resp) 247 if err != nil { 248 err = autorest.NewErrorWithError(err, "timeseriesinsights.EventSourcesClient", "Get", resp, "Failure responding to request") 249 } 250 251 return 252} 253 254// GetPreparer prepares the Get request. 255func (client EventSourcesClient) GetPreparer(ctx context.Context, resourceGroupName string, environmentName string, eventSourceName string) (*http.Request, error) { 256 pathParameters := map[string]interface{}{ 257 "environmentName": autorest.Encode("path", environmentName), 258 "eventSourceName": autorest.Encode("path", eventSourceName), 259 "resourceGroupName": autorest.Encode("path", resourceGroupName), 260 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 261 } 262 263 const APIVersion = "2017-02-28-preview" 264 queryParameters := map[string]interface{}{ 265 "api-version": APIVersion, 266 } 267 268 preparer := autorest.CreatePreparer( 269 autorest.AsGet(), 270 autorest.WithBaseURL(client.BaseURI), 271 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.TimeSeriesInsights/environments/{environmentName}/eventSources/{eventSourceName}", pathParameters), 272 autorest.WithQueryParameters(queryParameters)) 273 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 274} 275 276// GetSender sends the Get request. The method will close the 277// http.Response Body if it receives an error. 278func (client EventSourcesClient) GetSender(req *http.Request) (*http.Response, error) { 279 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 280} 281 282// GetResponder handles the response to the Get request. The method always 283// closes the http.Response Body. 284func (client EventSourcesClient) GetResponder(resp *http.Response) (result EventSourceResourceModel, err error) { 285 err = autorest.Respond( 286 resp, 287 client.ByInspecting(), 288 azure.WithErrorUnlessStatusCode(http.StatusOK), 289 autorest.ByUnmarshallingJSON(&result), 290 autorest.ByClosing()) 291 result.Response = autorest.Response{Response: resp} 292 return 293} 294 295// ListByEnvironment lists all the available event sources associated with the subscription and within the specified 296// resource group and environment. 297// Parameters: 298// resourceGroupName - name of an Azure Resource group. 299// environmentName - the name of the Time Series Insights environment associated with the specified resource 300// group. 301func (client EventSourcesClient) ListByEnvironment(ctx context.Context, resourceGroupName string, environmentName string) (result EventSourceListResponse, err error) { 302 if tracing.IsEnabled() { 303 ctx = tracing.StartSpan(ctx, fqdn+"/EventSourcesClient.ListByEnvironment") 304 defer func() { 305 sc := -1 306 if result.Response.Response != nil { 307 sc = result.Response.Response.StatusCode 308 } 309 tracing.EndSpan(ctx, sc, err) 310 }() 311 } 312 req, err := client.ListByEnvironmentPreparer(ctx, resourceGroupName, environmentName) 313 if err != nil { 314 err = autorest.NewErrorWithError(err, "timeseriesinsights.EventSourcesClient", "ListByEnvironment", nil, "Failure preparing request") 315 return 316 } 317 318 resp, err := client.ListByEnvironmentSender(req) 319 if err != nil { 320 result.Response = autorest.Response{Response: resp} 321 err = autorest.NewErrorWithError(err, "timeseriesinsights.EventSourcesClient", "ListByEnvironment", resp, "Failure sending request") 322 return 323 } 324 325 result, err = client.ListByEnvironmentResponder(resp) 326 if err != nil { 327 err = autorest.NewErrorWithError(err, "timeseriesinsights.EventSourcesClient", "ListByEnvironment", resp, "Failure responding to request") 328 } 329 330 return 331} 332 333// ListByEnvironmentPreparer prepares the ListByEnvironment request. 334func (client EventSourcesClient) ListByEnvironmentPreparer(ctx context.Context, resourceGroupName string, environmentName string) (*http.Request, error) { 335 pathParameters := map[string]interface{}{ 336 "environmentName": autorest.Encode("path", environmentName), 337 "resourceGroupName": autorest.Encode("path", resourceGroupName), 338 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 339 } 340 341 const APIVersion = "2017-02-28-preview" 342 queryParameters := map[string]interface{}{ 343 "api-version": APIVersion, 344 } 345 346 preparer := autorest.CreatePreparer( 347 autorest.AsGet(), 348 autorest.WithBaseURL(client.BaseURI), 349 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.TimeSeriesInsights/environments/{environmentName}/eventSources", pathParameters), 350 autorest.WithQueryParameters(queryParameters)) 351 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 352} 353 354// ListByEnvironmentSender sends the ListByEnvironment request. The method will close the 355// http.Response Body if it receives an error. 356func (client EventSourcesClient) ListByEnvironmentSender(req *http.Request) (*http.Response, error) { 357 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 358} 359 360// ListByEnvironmentResponder handles the response to the ListByEnvironment request. The method always 361// closes the http.Response Body. 362func (client EventSourcesClient) ListByEnvironmentResponder(resp *http.Response) (result EventSourceListResponse, err error) { 363 err = autorest.Respond( 364 resp, 365 client.ByInspecting(), 366 azure.WithErrorUnlessStatusCode(http.StatusOK), 367 autorest.ByUnmarshallingJSON(&result), 368 autorest.ByClosing()) 369 result.Response = autorest.Response{Response: resp} 370 return 371} 372 373// Update updates the event source with the specified name in the specified subscription, resource group, and 374// environment. 375// Parameters: 376// resourceGroupName - name of an Azure Resource group. 377// environmentName - the name of the Time Series Insights environment associated with the specified resource 378// group. 379// eventSourceName - the name of the Time Series Insights event source associated with the specified 380// environment. 381// eventSourceUpdateParameters - request object that contains the updated information for the event source. 382func (client EventSourcesClient) Update(ctx context.Context, resourceGroupName string, environmentName string, eventSourceName string, eventSourceUpdateParameters EventSourceUpdateParameters) (result EventSourceResourceModel, err error) { 383 if tracing.IsEnabled() { 384 ctx = tracing.StartSpan(ctx, fqdn+"/EventSourcesClient.Update") 385 defer func() { 386 sc := -1 387 if result.Response.Response != nil { 388 sc = result.Response.Response.StatusCode 389 } 390 tracing.EndSpan(ctx, sc, err) 391 }() 392 } 393 req, err := client.UpdatePreparer(ctx, resourceGroupName, environmentName, eventSourceName, eventSourceUpdateParameters) 394 if err != nil { 395 err = autorest.NewErrorWithError(err, "timeseriesinsights.EventSourcesClient", "Update", nil, "Failure preparing request") 396 return 397 } 398 399 resp, err := client.UpdateSender(req) 400 if err != nil { 401 result.Response = autorest.Response{Response: resp} 402 err = autorest.NewErrorWithError(err, "timeseriesinsights.EventSourcesClient", "Update", resp, "Failure sending request") 403 return 404 } 405 406 result, err = client.UpdateResponder(resp) 407 if err != nil { 408 err = autorest.NewErrorWithError(err, "timeseriesinsights.EventSourcesClient", "Update", resp, "Failure responding to request") 409 } 410 411 return 412} 413 414// UpdatePreparer prepares the Update request. 415func (client EventSourcesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, environmentName string, eventSourceName string, eventSourceUpdateParameters EventSourceUpdateParameters) (*http.Request, error) { 416 pathParameters := map[string]interface{}{ 417 "environmentName": autorest.Encode("path", environmentName), 418 "eventSourceName": autorest.Encode("path", eventSourceName), 419 "resourceGroupName": autorest.Encode("path", resourceGroupName), 420 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 421 } 422 423 const APIVersion = "2017-02-28-preview" 424 queryParameters := map[string]interface{}{ 425 "api-version": APIVersion, 426 } 427 428 preparer := autorest.CreatePreparer( 429 autorest.AsContentType("application/json; charset=utf-8"), 430 autorest.AsPatch(), 431 autorest.WithBaseURL(client.BaseURI), 432 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.TimeSeriesInsights/environments/{environmentName}/eventSources/{eventSourceName}", pathParameters), 433 autorest.WithJSON(eventSourceUpdateParameters), 434 autorest.WithQueryParameters(queryParameters)) 435 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 436} 437 438// UpdateSender sends the Update request. The method will close the 439// http.Response Body if it receives an error. 440func (client EventSourcesClient) UpdateSender(req *http.Request) (*http.Response, error) { 441 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 442} 443 444// UpdateResponder handles the response to the Update request. The method always 445// closes the http.Response Body. 446func (client EventSourcesClient) UpdateResponder(resp *http.Response) (result EventSourceResourceModel, err error) { 447 err = autorest.Respond( 448 resp, 449 client.ByInspecting(), 450 azure.WithErrorUnlessStatusCode(http.StatusOK), 451 autorest.ByUnmarshallingJSON(&result), 452 autorest.ByClosing()) 453 result.Response = autorest.Response{Response: resp} 454 return 455} 456