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