1package operationalinsights 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 9import ( 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// LinkedStorageAccountsClient is the operational Insights Client 19type LinkedStorageAccountsClient struct { 20 BaseClient 21} 22 23// NewLinkedStorageAccountsClient creates an instance of the LinkedStorageAccountsClient client. 24func NewLinkedStorageAccountsClient(subscriptionID string) LinkedStorageAccountsClient { 25 return NewLinkedStorageAccountsClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewLinkedStorageAccountsClientWithBaseURI creates an instance of the LinkedStorageAccountsClient client using a 29// custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, 30// Azure stack). 31func NewLinkedStorageAccountsClientWithBaseURI(baseURI string, subscriptionID string) LinkedStorageAccountsClient { 32 return LinkedStorageAccountsClient{NewWithBaseURI(baseURI, subscriptionID)} 33} 34 35// CreateOrUpdate create or Update a link relation between current workspace and a group of storage accounts of a 36// specific data source type. 37// Parameters: 38// resourceGroupName - the name of the resource group. The name is case insensitive. 39// workspaceName - the name of the workspace. 40// dataSourceType - linked storage accounts type. 41// parameters - the parameters required to create or update linked storage accounts. 42func (client LinkedStorageAccountsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, workspaceName string, dataSourceType DataSourceType, parameters LinkedStorageAccountsResource) (result LinkedStorageAccountsResource, err error) { 43 if tracing.IsEnabled() { 44 ctx = tracing.StartSpan(ctx, fqdn+"/LinkedStorageAccountsClient.CreateOrUpdate") 45 defer func() { 46 sc := -1 47 if result.Response.Response != nil { 48 sc = result.Response.Response.StatusCode 49 } 50 tracing.EndSpan(ctx, sc, err) 51 }() 52 } 53 if err := validation.Validate([]validation.Validation{ 54 {TargetValue: resourceGroupName, 55 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 56 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 57 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 58 {TargetValue: workspaceName, 59 Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 63, Chain: nil}, 60 {Target: "workspaceName", Name: validation.MinLength, Rule: 4, Chain: nil}, 61 {Target: "workspaceName", Name: validation.Pattern, Rule: `^[A-Za-z0-9][A-Za-z0-9-]+[A-Za-z0-9]$`, Chain: nil}}}, 62 {TargetValue: parameters, 63 Constraints: []validation.Constraint{{Target: "parameters.LinkedStorageAccountsProperties", Name: validation.Null, Rule: true, Chain: nil}}}, 64 {TargetValue: client.SubscriptionID, 65 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 66 return result, validation.NewError("operationalinsights.LinkedStorageAccountsClient", "CreateOrUpdate", err.Error()) 67 } 68 69 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, workspaceName, dataSourceType, parameters) 70 if err != nil { 71 err = autorest.NewErrorWithError(err, "operationalinsights.LinkedStorageAccountsClient", "CreateOrUpdate", nil, "Failure preparing request") 72 return 73 } 74 75 resp, err := client.CreateOrUpdateSender(req) 76 if err != nil { 77 result.Response = autorest.Response{Response: resp} 78 err = autorest.NewErrorWithError(err, "operationalinsights.LinkedStorageAccountsClient", "CreateOrUpdate", resp, "Failure sending request") 79 return 80 } 81 82 result, err = client.CreateOrUpdateResponder(resp) 83 if err != nil { 84 err = autorest.NewErrorWithError(err, "operationalinsights.LinkedStorageAccountsClient", "CreateOrUpdate", resp, "Failure responding to request") 85 return 86 } 87 88 return 89} 90 91// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 92func (client LinkedStorageAccountsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, workspaceName string, dataSourceType DataSourceType, parameters LinkedStorageAccountsResource) (*http.Request, error) { 93 pathParameters := map[string]interface{}{ 94 "dataSourceType": autorest.Encode("path", dataSourceType), 95 "resourceGroupName": autorest.Encode("path", resourceGroupName), 96 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 97 "workspaceName": autorest.Encode("path", workspaceName), 98 } 99 100 const APIVersion = "2020-08-01" 101 queryParameters := map[string]interface{}{ 102 "api-version": APIVersion, 103 } 104 105 preparer := autorest.CreatePreparer( 106 autorest.AsContentType("application/json; charset=utf-8"), 107 autorest.AsPut(), 108 autorest.WithBaseURL(client.BaseURI), 109 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/linkedStorageAccounts/{dataSourceType}", pathParameters), 110 autorest.WithJSON(parameters), 111 autorest.WithQueryParameters(queryParameters)) 112 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 113} 114 115// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 116// http.Response Body if it receives an error. 117func (client LinkedStorageAccountsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 118 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 119} 120 121// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 122// closes the http.Response Body. 123func (client LinkedStorageAccountsClient) CreateOrUpdateResponder(resp *http.Response) (result LinkedStorageAccountsResource, err error) { 124 err = autorest.Respond( 125 resp, 126 azure.WithErrorUnlessStatusCode(http.StatusOK), 127 autorest.ByUnmarshallingJSON(&result), 128 autorest.ByClosing()) 129 result.Response = autorest.Response{Response: resp} 130 return 131} 132 133// Delete deletes all linked storage accounts of a specific data source type associated with the specified workspace. 134// Parameters: 135// resourceGroupName - the name of the resource group. The name is case insensitive. 136// workspaceName - the name of the workspace. 137// dataSourceType - linked storage accounts type. 138func (client LinkedStorageAccountsClient) Delete(ctx context.Context, resourceGroupName string, workspaceName string, dataSourceType DataSourceType) (result autorest.Response, err error) { 139 if tracing.IsEnabled() { 140 ctx = tracing.StartSpan(ctx, fqdn+"/LinkedStorageAccountsClient.Delete") 141 defer func() { 142 sc := -1 143 if result.Response != nil { 144 sc = result.Response.StatusCode 145 } 146 tracing.EndSpan(ctx, sc, err) 147 }() 148 } 149 if err := validation.Validate([]validation.Validation{ 150 {TargetValue: resourceGroupName, 151 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 152 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 153 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 154 {TargetValue: workspaceName, 155 Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 63, Chain: nil}, 156 {Target: "workspaceName", Name: validation.MinLength, Rule: 4, Chain: nil}, 157 {Target: "workspaceName", Name: validation.Pattern, Rule: `^[A-Za-z0-9][A-Za-z0-9-]+[A-Za-z0-9]$`, Chain: nil}}}, 158 {TargetValue: client.SubscriptionID, 159 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 160 return result, validation.NewError("operationalinsights.LinkedStorageAccountsClient", "Delete", err.Error()) 161 } 162 163 req, err := client.DeletePreparer(ctx, resourceGroupName, workspaceName, dataSourceType) 164 if err != nil { 165 err = autorest.NewErrorWithError(err, "operationalinsights.LinkedStorageAccountsClient", "Delete", nil, "Failure preparing request") 166 return 167 } 168 169 resp, err := client.DeleteSender(req) 170 if err != nil { 171 result.Response = resp 172 err = autorest.NewErrorWithError(err, "operationalinsights.LinkedStorageAccountsClient", "Delete", resp, "Failure sending request") 173 return 174 } 175 176 result, err = client.DeleteResponder(resp) 177 if err != nil { 178 err = autorest.NewErrorWithError(err, "operationalinsights.LinkedStorageAccountsClient", "Delete", resp, "Failure responding to request") 179 return 180 } 181 182 return 183} 184 185// DeletePreparer prepares the Delete request. 186func (client LinkedStorageAccountsClient) DeletePreparer(ctx context.Context, resourceGroupName string, workspaceName string, dataSourceType DataSourceType) (*http.Request, error) { 187 pathParameters := map[string]interface{}{ 188 "dataSourceType": autorest.Encode("path", dataSourceType), 189 "resourceGroupName": autorest.Encode("path", resourceGroupName), 190 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 191 "workspaceName": autorest.Encode("path", workspaceName), 192 } 193 194 const APIVersion = "2020-08-01" 195 queryParameters := map[string]interface{}{ 196 "api-version": APIVersion, 197 } 198 199 preparer := autorest.CreatePreparer( 200 autorest.AsDelete(), 201 autorest.WithBaseURL(client.BaseURI), 202 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/linkedStorageAccounts/{dataSourceType}", pathParameters), 203 autorest.WithQueryParameters(queryParameters)) 204 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 205} 206 207// DeleteSender sends the Delete request. The method will close the 208// http.Response Body if it receives an error. 209func (client LinkedStorageAccountsClient) DeleteSender(req *http.Request) (*http.Response, error) { 210 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 211} 212 213// DeleteResponder handles the response to the Delete request. The method always 214// closes the http.Response Body. 215func (client LinkedStorageAccountsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 216 err = autorest.Respond( 217 resp, 218 azure.WithErrorUnlessStatusCode(http.StatusOK), 219 autorest.ByClosing()) 220 result.Response = resp 221 return 222} 223 224// Get gets all linked storage account of a specific data source type associated with the specified workspace. 225// Parameters: 226// resourceGroupName - the name of the resource group. The name is case insensitive. 227// workspaceName - the name of the workspace. 228// dataSourceType - linked storage accounts type. 229func (client LinkedStorageAccountsClient) Get(ctx context.Context, resourceGroupName string, workspaceName string, dataSourceType DataSourceType) (result LinkedStorageAccountsResource, err error) { 230 if tracing.IsEnabled() { 231 ctx = tracing.StartSpan(ctx, fqdn+"/LinkedStorageAccountsClient.Get") 232 defer func() { 233 sc := -1 234 if result.Response.Response != nil { 235 sc = result.Response.Response.StatusCode 236 } 237 tracing.EndSpan(ctx, sc, err) 238 }() 239 } 240 if err := validation.Validate([]validation.Validation{ 241 {TargetValue: resourceGroupName, 242 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 243 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 244 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 245 {TargetValue: workspaceName, 246 Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 63, Chain: nil}, 247 {Target: "workspaceName", Name: validation.MinLength, Rule: 4, Chain: nil}, 248 {Target: "workspaceName", Name: validation.Pattern, Rule: `^[A-Za-z0-9][A-Za-z0-9-]+[A-Za-z0-9]$`, Chain: nil}}}, 249 {TargetValue: client.SubscriptionID, 250 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 251 return result, validation.NewError("operationalinsights.LinkedStorageAccountsClient", "Get", err.Error()) 252 } 253 254 req, err := client.GetPreparer(ctx, resourceGroupName, workspaceName, dataSourceType) 255 if err != nil { 256 err = autorest.NewErrorWithError(err, "operationalinsights.LinkedStorageAccountsClient", "Get", nil, "Failure preparing request") 257 return 258 } 259 260 resp, err := client.GetSender(req) 261 if err != nil { 262 result.Response = autorest.Response{Response: resp} 263 err = autorest.NewErrorWithError(err, "operationalinsights.LinkedStorageAccountsClient", "Get", resp, "Failure sending request") 264 return 265 } 266 267 result, err = client.GetResponder(resp) 268 if err != nil { 269 err = autorest.NewErrorWithError(err, "operationalinsights.LinkedStorageAccountsClient", "Get", resp, "Failure responding to request") 270 return 271 } 272 273 return 274} 275 276// GetPreparer prepares the Get request. 277func (client LinkedStorageAccountsClient) GetPreparer(ctx context.Context, resourceGroupName string, workspaceName string, dataSourceType DataSourceType) (*http.Request, error) { 278 pathParameters := map[string]interface{}{ 279 "dataSourceType": autorest.Encode("path", dataSourceType), 280 "resourceGroupName": autorest.Encode("path", resourceGroupName), 281 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 282 "workspaceName": autorest.Encode("path", workspaceName), 283 } 284 285 const APIVersion = "2020-08-01" 286 queryParameters := map[string]interface{}{ 287 "api-version": APIVersion, 288 } 289 290 preparer := autorest.CreatePreparer( 291 autorest.AsGet(), 292 autorest.WithBaseURL(client.BaseURI), 293 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/linkedStorageAccounts/{dataSourceType}", pathParameters), 294 autorest.WithQueryParameters(queryParameters)) 295 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 296} 297 298// GetSender sends the Get request. The method will close the 299// http.Response Body if it receives an error. 300func (client LinkedStorageAccountsClient) GetSender(req *http.Request) (*http.Response, error) { 301 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 302} 303 304// GetResponder handles the response to the Get request. The method always 305// closes the http.Response Body. 306func (client LinkedStorageAccountsClient) GetResponder(resp *http.Response) (result LinkedStorageAccountsResource, err error) { 307 err = autorest.Respond( 308 resp, 309 azure.WithErrorUnlessStatusCode(http.StatusOK), 310 autorest.ByUnmarshallingJSON(&result), 311 autorest.ByClosing()) 312 result.Response = autorest.Response{Response: resp} 313 return 314} 315 316// ListByWorkspace gets all linked storage accounts associated with the specified workspace, storage accounts will be 317// sorted by their data source type. 318// Parameters: 319// resourceGroupName - the name of the resource group. The name is case insensitive. 320// workspaceName - the name of the workspace. 321func (client LinkedStorageAccountsClient) ListByWorkspace(ctx context.Context, resourceGroupName string, workspaceName string) (result LinkedStorageAccountsListResult, err error) { 322 if tracing.IsEnabled() { 323 ctx = tracing.StartSpan(ctx, fqdn+"/LinkedStorageAccountsClient.ListByWorkspace") 324 defer func() { 325 sc := -1 326 if result.Response.Response != nil { 327 sc = result.Response.Response.StatusCode 328 } 329 tracing.EndSpan(ctx, sc, err) 330 }() 331 } 332 if err := validation.Validate([]validation.Validation{ 333 {TargetValue: client.SubscriptionID, 334 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 335 {TargetValue: resourceGroupName, 336 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 337 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 338 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 339 {TargetValue: workspaceName, 340 Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 63, Chain: nil}, 341 {Target: "workspaceName", Name: validation.MinLength, Rule: 4, Chain: nil}, 342 {Target: "workspaceName", Name: validation.Pattern, Rule: `^[A-Za-z0-9][A-Za-z0-9-]+[A-Za-z0-9]$`, Chain: nil}}}}); err != nil { 343 return result, validation.NewError("operationalinsights.LinkedStorageAccountsClient", "ListByWorkspace", err.Error()) 344 } 345 346 req, err := client.ListByWorkspacePreparer(ctx, resourceGroupName, workspaceName) 347 if err != nil { 348 err = autorest.NewErrorWithError(err, "operationalinsights.LinkedStorageAccountsClient", "ListByWorkspace", nil, "Failure preparing request") 349 return 350 } 351 352 resp, err := client.ListByWorkspaceSender(req) 353 if err != nil { 354 result.Response = autorest.Response{Response: resp} 355 err = autorest.NewErrorWithError(err, "operationalinsights.LinkedStorageAccountsClient", "ListByWorkspace", resp, "Failure sending request") 356 return 357 } 358 359 result, err = client.ListByWorkspaceResponder(resp) 360 if err != nil { 361 err = autorest.NewErrorWithError(err, "operationalinsights.LinkedStorageAccountsClient", "ListByWorkspace", resp, "Failure responding to request") 362 return 363 } 364 365 return 366} 367 368// ListByWorkspacePreparer prepares the ListByWorkspace request. 369func (client LinkedStorageAccountsClient) ListByWorkspacePreparer(ctx context.Context, resourceGroupName string, workspaceName string) (*http.Request, error) { 370 pathParameters := map[string]interface{}{ 371 "resourceGroupName": autorest.Encode("path", resourceGroupName), 372 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 373 "workspaceName": autorest.Encode("path", workspaceName), 374 } 375 376 const APIVersion = "2020-08-01" 377 queryParameters := map[string]interface{}{ 378 "api-version": APIVersion, 379 } 380 381 preparer := autorest.CreatePreparer( 382 autorest.AsGet(), 383 autorest.WithBaseURL(client.BaseURI), 384 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/linkedStorageAccounts", pathParameters), 385 autorest.WithQueryParameters(queryParameters)) 386 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 387} 388 389// ListByWorkspaceSender sends the ListByWorkspace request. The method will close the 390// http.Response Body if it receives an error. 391func (client LinkedStorageAccountsClient) ListByWorkspaceSender(req *http.Request) (*http.Response, error) { 392 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 393} 394 395// ListByWorkspaceResponder handles the response to the ListByWorkspace request. The method always 396// closes the http.Response Body. 397func (client LinkedStorageAccountsClient) ListByWorkspaceResponder(resp *http.Response) (result LinkedStorageAccountsListResult, err error) { 398 err = autorest.Respond( 399 resp, 400 azure.WithErrorUnlessStatusCode(http.StatusOK), 401 autorest.ByUnmarshallingJSON(&result), 402 autorest.ByClosing()) 403 result.Response = autorest.Response{Response: resp} 404 return 405} 406