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