1package datafactory 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// DatasetsClient is the the Azure Data Factory V2 management API provides a RESTful set of web services that interact 19// with Azure Data Factory V2 services. 20type DatasetsClient struct { 21 BaseClient 22} 23 24// NewDatasetsClient creates an instance of the DatasetsClient client. 25func NewDatasetsClient(subscriptionID string) DatasetsClient { 26 return NewDatasetsClientWithBaseURI(DefaultBaseURI, subscriptionID) 27} 28 29// NewDatasetsClientWithBaseURI creates an instance of the DatasetsClient client using a custom endpoint. Use this 30// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 31func NewDatasetsClientWithBaseURI(baseURI string, subscriptionID string) DatasetsClient { 32 return DatasetsClient{NewWithBaseURI(baseURI, subscriptionID)} 33} 34 35// CreateOrUpdate creates or updates a dataset. 36// Parameters: 37// resourceGroupName - the resource group name. 38// factoryName - the factory name. 39// datasetName - the dataset name. 40// dataset - dataset resource definition. 41// ifMatch - eTag of the dataset entity. Should only be specified for update, for which it should match 42// existing entity or can be * for unconditional update. 43func (client DatasetsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, factoryName string, datasetName string, dataset DatasetResource, ifMatch string) (result DatasetResource, err error) { 44 if tracing.IsEnabled() { 45 ctx = tracing.StartSpan(ctx, fqdn+"/DatasetsClient.CreateOrUpdate") 46 defer func() { 47 sc := -1 48 if result.Response.Response != nil { 49 sc = result.Response.Response.StatusCode 50 } 51 tracing.EndSpan(ctx, sc, err) 52 }() 53 } 54 if err := validation.Validate([]validation.Validation{ 55 {TargetValue: resourceGroupName, 56 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 57 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 58 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 59 {TargetValue: factoryName, 60 Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil}, 61 {Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil}, 62 {Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}}, 63 {TargetValue: datasetName, 64 Constraints: []validation.Constraint{{Target: "datasetName", Name: validation.MaxLength, Rule: 260, Chain: nil}, 65 {Target: "datasetName", Name: validation.MinLength, Rule: 1, Chain: nil}, 66 {Target: "datasetName", Name: validation.Pattern, Rule: `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`, Chain: nil}}}}); err != nil { 67 return result, validation.NewError("datafactory.DatasetsClient", "CreateOrUpdate", err.Error()) 68 } 69 70 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, factoryName, datasetName, dataset, ifMatch) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "CreateOrUpdate", nil, "Failure preparing request") 73 return 74 } 75 76 resp, err := client.CreateOrUpdateSender(req) 77 if err != nil { 78 result.Response = autorest.Response{Response: resp} 79 err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "CreateOrUpdate", resp, "Failure sending request") 80 return 81 } 82 83 result, err = client.CreateOrUpdateResponder(resp) 84 if err != nil { 85 err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "CreateOrUpdate", resp, "Failure responding to request") 86 return 87 } 88 89 return 90} 91 92// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 93func (client DatasetsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, factoryName string, datasetName string, dataset DatasetResource, ifMatch string) (*http.Request, error) { 94 pathParameters := map[string]interface{}{ 95 "datasetName": autorest.Encode("path", datasetName), 96 "factoryName": autorest.Encode("path", factoryName), 97 "resourceGroupName": autorest.Encode("path", resourceGroupName), 98 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 99 } 100 101 const APIVersion = "2017-09-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.DataFactory/factories/{factoryName}/datasets/{datasetName}", pathParameters), 111 autorest.WithJSON(dataset), 112 autorest.WithQueryParameters(queryParameters)) 113 if len(ifMatch) > 0 { 114 preparer = autorest.DecoratePreparer(preparer, 115 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 116 } 117 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 118} 119 120// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 121// http.Response Body if it receives an error. 122func (client DatasetsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 123 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 124} 125 126// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 127// closes the http.Response Body. 128func (client DatasetsClient) CreateOrUpdateResponder(resp *http.Response) (result DatasetResource, err error) { 129 err = autorest.Respond( 130 resp, 131 azure.WithErrorUnlessStatusCode(http.StatusOK), 132 autorest.ByUnmarshallingJSON(&result), 133 autorest.ByClosing()) 134 result.Response = autorest.Response{Response: resp} 135 return 136} 137 138// Delete deletes a dataset. 139// Parameters: 140// resourceGroupName - the resource group name. 141// factoryName - the factory name. 142// datasetName - the dataset name. 143func (client DatasetsClient) Delete(ctx context.Context, resourceGroupName string, factoryName string, datasetName string) (result autorest.Response, err error) { 144 if tracing.IsEnabled() { 145 ctx = tracing.StartSpan(ctx, fqdn+"/DatasetsClient.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 if err := validation.Validate([]validation.Validation{ 155 {TargetValue: resourceGroupName, 156 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 157 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 158 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 159 {TargetValue: factoryName, 160 Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil}, 161 {Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil}, 162 {Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}}, 163 {TargetValue: datasetName, 164 Constraints: []validation.Constraint{{Target: "datasetName", Name: validation.MaxLength, Rule: 260, Chain: nil}, 165 {Target: "datasetName", Name: validation.MinLength, Rule: 1, Chain: nil}, 166 {Target: "datasetName", Name: validation.Pattern, Rule: `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`, Chain: nil}}}}); err != nil { 167 return result, validation.NewError("datafactory.DatasetsClient", "Delete", err.Error()) 168 } 169 170 req, err := client.DeletePreparer(ctx, resourceGroupName, factoryName, datasetName) 171 if err != nil { 172 err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Delete", nil, "Failure preparing request") 173 return 174 } 175 176 resp, err := client.DeleteSender(req) 177 if err != nil { 178 result.Response = resp 179 err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Delete", resp, "Failure sending request") 180 return 181 } 182 183 result, err = client.DeleteResponder(resp) 184 if err != nil { 185 err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Delete", resp, "Failure responding to request") 186 return 187 } 188 189 return 190} 191 192// DeletePreparer prepares the Delete request. 193func (client DatasetsClient) DeletePreparer(ctx context.Context, resourceGroupName string, factoryName string, datasetName string) (*http.Request, error) { 194 pathParameters := map[string]interface{}{ 195 "datasetName": autorest.Encode("path", datasetName), 196 "factoryName": autorest.Encode("path", factoryName), 197 "resourceGroupName": autorest.Encode("path", resourceGroupName), 198 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 199 } 200 201 const APIVersion = "2017-09-01-preview" 202 queryParameters := map[string]interface{}{ 203 "api-version": APIVersion, 204 } 205 206 preparer := autorest.CreatePreparer( 207 autorest.AsDelete(), 208 autorest.WithBaseURL(client.BaseURI), 209 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/datasets/{datasetName}", pathParameters), 210 autorest.WithQueryParameters(queryParameters)) 211 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 212} 213 214// DeleteSender sends the Delete request. The method will close the 215// http.Response Body if it receives an error. 216func (client DatasetsClient) DeleteSender(req *http.Request) (*http.Response, error) { 217 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 218} 219 220// DeleteResponder handles the response to the Delete request. The method always 221// closes the http.Response Body. 222func (client DatasetsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 223 err = autorest.Respond( 224 resp, 225 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 226 autorest.ByClosing()) 227 result.Response = resp 228 return 229} 230 231// Get gets a dataset. 232// Parameters: 233// resourceGroupName - the resource group name. 234// factoryName - the factory name. 235// datasetName - the dataset name. 236func (client DatasetsClient) Get(ctx context.Context, resourceGroupName string, factoryName string, datasetName string) (result DatasetResource, err error) { 237 if tracing.IsEnabled() { 238 ctx = tracing.StartSpan(ctx, fqdn+"/DatasetsClient.Get") 239 defer func() { 240 sc := -1 241 if result.Response.Response != nil { 242 sc = result.Response.Response.StatusCode 243 } 244 tracing.EndSpan(ctx, sc, err) 245 }() 246 } 247 if err := validation.Validate([]validation.Validation{ 248 {TargetValue: resourceGroupName, 249 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 250 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 251 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 252 {TargetValue: factoryName, 253 Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil}, 254 {Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil}, 255 {Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}}, 256 {TargetValue: datasetName, 257 Constraints: []validation.Constraint{{Target: "datasetName", Name: validation.MaxLength, Rule: 260, Chain: nil}, 258 {Target: "datasetName", Name: validation.MinLength, Rule: 1, Chain: nil}, 259 {Target: "datasetName", Name: validation.Pattern, Rule: `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`, Chain: nil}}}}); err != nil { 260 return result, validation.NewError("datafactory.DatasetsClient", "Get", err.Error()) 261 } 262 263 req, err := client.GetPreparer(ctx, resourceGroupName, factoryName, datasetName) 264 if err != nil { 265 err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Get", nil, "Failure preparing request") 266 return 267 } 268 269 resp, err := client.GetSender(req) 270 if err != nil { 271 result.Response = autorest.Response{Response: resp} 272 err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Get", resp, "Failure sending request") 273 return 274 } 275 276 result, err = client.GetResponder(resp) 277 if err != nil { 278 err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "Get", resp, "Failure responding to request") 279 return 280 } 281 282 return 283} 284 285// GetPreparer prepares the Get request. 286func (client DatasetsClient) GetPreparer(ctx context.Context, resourceGroupName string, factoryName string, datasetName string) (*http.Request, error) { 287 pathParameters := map[string]interface{}{ 288 "datasetName": autorest.Encode("path", datasetName), 289 "factoryName": autorest.Encode("path", factoryName), 290 "resourceGroupName": autorest.Encode("path", resourceGroupName), 291 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 292 } 293 294 const APIVersion = "2017-09-01-preview" 295 queryParameters := map[string]interface{}{ 296 "api-version": APIVersion, 297 } 298 299 preparer := autorest.CreatePreparer( 300 autorest.AsGet(), 301 autorest.WithBaseURL(client.BaseURI), 302 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/datasets/{datasetName}", pathParameters), 303 autorest.WithQueryParameters(queryParameters)) 304 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 305} 306 307// GetSender sends the Get request. The method will close the 308// http.Response Body if it receives an error. 309func (client DatasetsClient) GetSender(req *http.Request) (*http.Response, error) { 310 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 311} 312 313// GetResponder handles the response to the Get request. The method always 314// closes the http.Response Body. 315func (client DatasetsClient) GetResponder(resp *http.Response) (result DatasetResource, err error) { 316 err = autorest.Respond( 317 resp, 318 azure.WithErrorUnlessStatusCode(http.StatusOK), 319 autorest.ByUnmarshallingJSON(&result), 320 autorest.ByClosing()) 321 result.Response = autorest.Response{Response: resp} 322 return 323} 324 325// ListByFactory lists datasets. 326// Parameters: 327// resourceGroupName - the resource group name. 328// factoryName - the factory name. 329func (client DatasetsClient) ListByFactory(ctx context.Context, resourceGroupName string, factoryName string) (result DatasetListResponsePage, err error) { 330 if tracing.IsEnabled() { 331 ctx = tracing.StartSpan(ctx, fqdn+"/DatasetsClient.ListByFactory") 332 defer func() { 333 sc := -1 334 if result.dlr.Response.Response != nil { 335 sc = result.dlr.Response.Response.StatusCode 336 } 337 tracing.EndSpan(ctx, sc, err) 338 }() 339 } 340 if err := validation.Validate([]validation.Validation{ 341 {TargetValue: resourceGroupName, 342 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 343 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 344 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 345 {TargetValue: factoryName, 346 Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil}, 347 {Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil}, 348 {Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}}}); err != nil { 349 return result, validation.NewError("datafactory.DatasetsClient", "ListByFactory", err.Error()) 350 } 351 352 result.fn = client.listByFactoryNextResults 353 req, err := client.ListByFactoryPreparer(ctx, resourceGroupName, factoryName) 354 if err != nil { 355 err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "ListByFactory", nil, "Failure preparing request") 356 return 357 } 358 359 resp, err := client.ListByFactorySender(req) 360 if err != nil { 361 result.dlr.Response = autorest.Response{Response: resp} 362 err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "ListByFactory", resp, "Failure sending request") 363 return 364 } 365 366 result.dlr, err = client.ListByFactoryResponder(resp) 367 if err != nil { 368 err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "ListByFactory", resp, "Failure responding to request") 369 return 370 } 371 if result.dlr.hasNextLink() && result.dlr.IsEmpty() { 372 err = result.NextWithContext(ctx) 373 return 374 } 375 376 return 377} 378 379// ListByFactoryPreparer prepares the ListByFactory request. 380func (client DatasetsClient) ListByFactoryPreparer(ctx context.Context, resourceGroupName string, factoryName string) (*http.Request, error) { 381 pathParameters := map[string]interface{}{ 382 "factoryName": autorest.Encode("path", factoryName), 383 "resourceGroupName": autorest.Encode("path", resourceGroupName), 384 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 385 } 386 387 const APIVersion = "2017-09-01-preview" 388 queryParameters := map[string]interface{}{ 389 "api-version": APIVersion, 390 } 391 392 preparer := autorest.CreatePreparer( 393 autorest.AsGet(), 394 autorest.WithBaseURL(client.BaseURI), 395 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/datasets", pathParameters), 396 autorest.WithQueryParameters(queryParameters)) 397 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 398} 399 400// ListByFactorySender sends the ListByFactory request. The method will close the 401// http.Response Body if it receives an error. 402func (client DatasetsClient) ListByFactorySender(req *http.Request) (*http.Response, error) { 403 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 404} 405 406// ListByFactoryResponder handles the response to the ListByFactory request. The method always 407// closes the http.Response Body. 408func (client DatasetsClient) ListByFactoryResponder(resp *http.Response) (result DatasetListResponse, err error) { 409 err = autorest.Respond( 410 resp, 411 azure.WithErrorUnlessStatusCode(http.StatusOK), 412 autorest.ByUnmarshallingJSON(&result), 413 autorest.ByClosing()) 414 result.Response = autorest.Response{Response: resp} 415 return 416} 417 418// listByFactoryNextResults retrieves the next set of results, if any. 419func (client DatasetsClient) listByFactoryNextResults(ctx context.Context, lastResults DatasetListResponse) (result DatasetListResponse, err error) { 420 req, err := lastResults.datasetListResponsePreparer(ctx) 421 if err != nil { 422 return result, autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "listByFactoryNextResults", nil, "Failure preparing next results request") 423 } 424 if req == nil { 425 return 426 } 427 resp, err := client.ListByFactorySender(req) 428 if err != nil { 429 result.Response = autorest.Response{Response: resp} 430 return result, autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "listByFactoryNextResults", resp, "Failure sending next results request") 431 } 432 result, err = client.ListByFactoryResponder(resp) 433 if err != nil { 434 err = autorest.NewErrorWithError(err, "datafactory.DatasetsClient", "listByFactoryNextResults", resp, "Failure responding to next results request") 435 } 436 return 437} 438 439// ListByFactoryComplete enumerates all values, automatically crossing page boundaries as required. 440func (client DatasetsClient) ListByFactoryComplete(ctx context.Context, resourceGroupName string, factoryName string) (result DatasetListResponseIterator, err error) { 441 if tracing.IsEnabled() { 442 ctx = tracing.StartSpan(ctx, fqdn+"/DatasetsClient.ListByFactory") 443 defer func() { 444 sc := -1 445 if result.Response().Response.Response != nil { 446 sc = result.page.Response().Response.Response.StatusCode 447 } 448 tracing.EndSpan(ctx, sc, err) 449 }() 450 } 451 result.page, err = client.ListByFactory(ctx, resourceGroupName, factoryName) 452 return 453} 454