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