1package apimanagement 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// TenantConfigurationClient is the apiManagement Client 29type TenantConfigurationClient struct { 30 BaseClient 31} 32 33// NewTenantConfigurationClient creates an instance of the TenantConfigurationClient client. 34func NewTenantConfigurationClient(subscriptionID string) TenantConfigurationClient { 35 return NewTenantConfigurationClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewTenantConfigurationClientWithBaseURI creates an instance of the TenantConfigurationClient client. 39func NewTenantConfigurationClientWithBaseURI(baseURI string, subscriptionID string) TenantConfigurationClient { 40 return TenantConfigurationClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// Deploy this operation applies changes from the specified Git branch to the configuration database. This is a long 44// running operation and could take several minutes to complete. 45// Parameters: 46// resourceGroupName - the name of the resource group. 47// serviceName - the name of the API Management service. 48// parameters - deploy Configuration parameters. 49func (client TenantConfigurationClient) Deploy(ctx context.Context, resourceGroupName string, serviceName string, parameters DeployConfigurationParameters) (result TenantConfigurationDeployFuture, err error) { 50 if err := validation.Validate([]validation.Validation{ 51 {TargetValue: serviceName, 52 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 53 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 54 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 55 {TargetValue: parameters, 56 Constraints: []validation.Constraint{{Target: "parameters.Branch", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 57 return result, validation.NewError("apimanagement.TenantConfigurationClient", "Deploy", err.Error()) 58 } 59 60 req, err := client.DeployPreparer(ctx, resourceGroupName, serviceName, parameters) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Deploy", nil, "Failure preparing request") 63 return 64 } 65 66 result, err = client.DeploySender(req) 67 if err != nil { 68 err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Deploy", result.Response(), "Failure sending request") 69 return 70 } 71 72 return 73} 74 75// DeployPreparer prepares the Deploy request. 76func (client TenantConfigurationClient) DeployPreparer(ctx context.Context, resourceGroupName string, serviceName string, parameters DeployConfigurationParameters) (*http.Request, error) { 77 pathParameters := map[string]interface{}{ 78 "configurationName": autorest.Encode("path", "configuration"), 79 "resourceGroupName": autorest.Encode("path", resourceGroupName), 80 "serviceName": autorest.Encode("path", serviceName), 81 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 82 } 83 84 const APIVersion = "2018-01-01" 85 queryParameters := map[string]interface{}{ 86 "api-version": APIVersion, 87 } 88 89 preparer := autorest.CreatePreparer( 90 autorest.AsContentType("application/json; charset=utf-8"), 91 autorest.AsPost(), 92 autorest.WithBaseURL(client.BaseURI), 93 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/{configurationName}/deploy", pathParameters), 94 autorest.WithJSON(parameters), 95 autorest.WithQueryParameters(queryParameters)) 96 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 97} 98 99// DeploySender sends the Deploy request. The method will close the 100// http.Response Body if it receives an error. 101func (client TenantConfigurationClient) DeploySender(req *http.Request) (future TenantConfigurationDeployFuture, err error) { 102 sender := autorest.DecorateSender(client, azure.DoRetryWithRegistration(client.Client)) 103 future.Future = azure.NewFuture(req) 104 future.req = req 105 _, err = future.Done(sender) 106 if err != nil { 107 return 108 } 109 err = autorest.Respond(future.Response(), 110 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted)) 111 return 112} 113 114// DeployResponder handles the response to the Deploy request. The method always 115// closes the http.Response Body. 116func (client TenantConfigurationClient) DeployResponder(resp *http.Response) (result OperationResultContract, err error) { 117 err = autorest.Respond( 118 resp, 119 client.ByInspecting(), 120 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 121 autorest.ByUnmarshallingJSON(&result), 122 autorest.ByClosing()) 123 result.Response = autorest.Response{Response: resp} 124 return 125} 126 127// GetSyncState gets the status of the most recent synchronization between the configuration database and the Git 128// repository. 129// Parameters: 130// resourceGroupName - the name of the resource group. 131// serviceName - the name of the API Management service. 132func (client TenantConfigurationClient) GetSyncState(ctx context.Context, resourceGroupName string, serviceName string) (result TenantConfigurationSyncStateContract, err error) { 133 if err := validation.Validate([]validation.Validation{ 134 {TargetValue: serviceName, 135 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 136 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 137 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 138 return result, validation.NewError("apimanagement.TenantConfigurationClient", "GetSyncState", err.Error()) 139 } 140 141 req, err := client.GetSyncStatePreparer(ctx, resourceGroupName, serviceName) 142 if err != nil { 143 err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "GetSyncState", nil, "Failure preparing request") 144 return 145 } 146 147 resp, err := client.GetSyncStateSender(req) 148 if err != nil { 149 result.Response = autorest.Response{Response: resp} 150 err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "GetSyncState", resp, "Failure sending request") 151 return 152 } 153 154 result, err = client.GetSyncStateResponder(resp) 155 if err != nil { 156 err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "GetSyncState", resp, "Failure responding to request") 157 } 158 159 return 160} 161 162// GetSyncStatePreparer prepares the GetSyncState request. 163func (client TenantConfigurationClient) GetSyncStatePreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) { 164 pathParameters := map[string]interface{}{ 165 "configurationName": autorest.Encode("path", "configuration"), 166 "resourceGroupName": autorest.Encode("path", resourceGroupName), 167 "serviceName": autorest.Encode("path", serviceName), 168 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 169 } 170 171 const APIVersion = "2018-01-01" 172 queryParameters := map[string]interface{}{ 173 "api-version": APIVersion, 174 } 175 176 preparer := autorest.CreatePreparer( 177 autorest.AsGet(), 178 autorest.WithBaseURL(client.BaseURI), 179 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/{configurationName}/syncState", pathParameters), 180 autorest.WithQueryParameters(queryParameters)) 181 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 182} 183 184// GetSyncStateSender sends the GetSyncState request. The method will close the 185// http.Response Body if it receives an error. 186func (client TenantConfigurationClient) GetSyncStateSender(req *http.Request) (*http.Response, error) { 187 return autorest.SendWithSender(client, req, 188 azure.DoRetryWithRegistration(client.Client)) 189} 190 191// GetSyncStateResponder handles the response to the GetSyncState request. The method always 192// closes the http.Response Body. 193func (client TenantConfigurationClient) GetSyncStateResponder(resp *http.Response) (result TenantConfigurationSyncStateContract, err error) { 194 err = autorest.Respond( 195 resp, 196 client.ByInspecting(), 197 azure.WithErrorUnlessStatusCode(http.StatusOK), 198 autorest.ByUnmarshallingJSON(&result), 199 autorest.ByClosing()) 200 result.Response = autorest.Response{Response: resp} 201 return 202} 203 204// Save this operation creates a commit with the current configuration snapshot to the specified branch in the 205// repository. This is a long running operation and could take several minutes to complete. 206// Parameters: 207// resourceGroupName - the name of the resource group. 208// serviceName - the name of the API Management service. 209// parameters - save Configuration parameters. 210func (client TenantConfigurationClient) Save(ctx context.Context, resourceGroupName string, serviceName string, parameters SaveConfigurationParameter) (result TenantConfigurationSaveFuture, err error) { 211 if err := validation.Validate([]validation.Validation{ 212 {TargetValue: serviceName, 213 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 214 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 215 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 216 {TargetValue: parameters, 217 Constraints: []validation.Constraint{{Target: "parameters.Branch", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 218 return result, validation.NewError("apimanagement.TenantConfigurationClient", "Save", err.Error()) 219 } 220 221 req, err := client.SavePreparer(ctx, resourceGroupName, serviceName, parameters) 222 if err != nil { 223 err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Save", nil, "Failure preparing request") 224 return 225 } 226 227 result, err = client.SaveSender(req) 228 if err != nil { 229 err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Save", result.Response(), "Failure sending request") 230 return 231 } 232 233 return 234} 235 236// SavePreparer prepares the Save request. 237func (client TenantConfigurationClient) SavePreparer(ctx context.Context, resourceGroupName string, serviceName string, parameters SaveConfigurationParameter) (*http.Request, error) { 238 pathParameters := map[string]interface{}{ 239 "configurationName": autorest.Encode("path", "configuration"), 240 "resourceGroupName": autorest.Encode("path", resourceGroupName), 241 "serviceName": autorest.Encode("path", serviceName), 242 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 243 } 244 245 const APIVersion = "2018-01-01" 246 queryParameters := map[string]interface{}{ 247 "api-version": APIVersion, 248 } 249 250 preparer := autorest.CreatePreparer( 251 autorest.AsContentType("application/json; charset=utf-8"), 252 autorest.AsPost(), 253 autorest.WithBaseURL(client.BaseURI), 254 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/{configurationName}/save", pathParameters), 255 autorest.WithJSON(parameters), 256 autorest.WithQueryParameters(queryParameters)) 257 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 258} 259 260// SaveSender sends the Save request. The method will close the 261// http.Response Body if it receives an error. 262func (client TenantConfigurationClient) SaveSender(req *http.Request) (future TenantConfigurationSaveFuture, err error) { 263 sender := autorest.DecorateSender(client, azure.DoRetryWithRegistration(client.Client)) 264 future.Future = azure.NewFuture(req) 265 future.req = req 266 _, err = future.Done(sender) 267 if err != nil { 268 return 269 } 270 err = autorest.Respond(future.Response(), 271 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted)) 272 return 273} 274 275// SaveResponder handles the response to the Save request. The method always 276// closes the http.Response Body. 277func (client TenantConfigurationClient) SaveResponder(resp *http.Response) (result OperationResultContract, err error) { 278 err = autorest.Respond( 279 resp, 280 client.ByInspecting(), 281 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 282 autorest.ByUnmarshallingJSON(&result), 283 autorest.ByClosing()) 284 result.Response = autorest.Response{Response: resp} 285 return 286} 287 288// Validate this operation validates the changes in the specified Git branch. This is a long running operation and 289// could take several minutes to complete. 290// Parameters: 291// resourceGroupName - the name of the resource group. 292// serviceName - the name of the API Management service. 293// parameters - validate Configuration parameters. 294func (client TenantConfigurationClient) Validate(ctx context.Context, resourceGroupName string, serviceName string, parameters DeployConfigurationParameters) (result TenantConfigurationValidateFuture, err error) { 295 if err := validation.Validate([]validation.Validation{ 296 {TargetValue: serviceName, 297 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 298 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 299 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 300 {TargetValue: parameters, 301 Constraints: []validation.Constraint{{Target: "parameters.Branch", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 302 return result, validation.NewError("apimanagement.TenantConfigurationClient", "Validate", err.Error()) 303 } 304 305 req, err := client.ValidatePreparer(ctx, resourceGroupName, serviceName, parameters) 306 if err != nil { 307 err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Validate", nil, "Failure preparing request") 308 return 309 } 310 311 result, err = client.ValidateSender(req) 312 if err != nil { 313 err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Validate", result.Response(), "Failure sending request") 314 return 315 } 316 317 return 318} 319 320// ValidatePreparer prepares the Validate request. 321func (client TenantConfigurationClient) ValidatePreparer(ctx context.Context, resourceGroupName string, serviceName string, parameters DeployConfigurationParameters) (*http.Request, error) { 322 pathParameters := map[string]interface{}{ 323 "configurationName": autorest.Encode("path", "configuration"), 324 "resourceGroupName": autorest.Encode("path", resourceGroupName), 325 "serviceName": autorest.Encode("path", serviceName), 326 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 327 } 328 329 const APIVersion = "2018-01-01" 330 queryParameters := map[string]interface{}{ 331 "api-version": APIVersion, 332 } 333 334 preparer := autorest.CreatePreparer( 335 autorest.AsContentType("application/json; charset=utf-8"), 336 autorest.AsPost(), 337 autorest.WithBaseURL(client.BaseURI), 338 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/{configurationName}/validate", pathParameters), 339 autorest.WithJSON(parameters), 340 autorest.WithQueryParameters(queryParameters)) 341 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 342} 343 344// ValidateSender sends the Validate request. The method will close the 345// http.Response Body if it receives an error. 346func (client TenantConfigurationClient) ValidateSender(req *http.Request) (future TenantConfigurationValidateFuture, err error) { 347 sender := autorest.DecorateSender(client, azure.DoRetryWithRegistration(client.Client)) 348 future.Future = azure.NewFuture(req) 349 future.req = req 350 _, err = future.Done(sender) 351 if err != nil { 352 return 353 } 354 err = autorest.Respond(future.Response(), 355 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted)) 356 return 357} 358 359// ValidateResponder handles the response to the Validate request. The method always 360// closes the http.Response Body. 361func (client TenantConfigurationClient) ValidateResponder(resp *http.Response) (result OperationResultContract, err error) { 362 err = autorest.Respond( 363 resp, 364 client.ByInspecting(), 365 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 366 autorest.ByUnmarshallingJSON(&result), 367 autorest.ByClosing()) 368 result.Response = autorest.Response{Response: resp} 369 return 370} 371