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