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 "resourceGroupName": autorest.Encode("path", resourceGroupName), 79 "serviceName": autorest.Encode("path", serviceName), 80 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 81 } 82 83 const APIVersion = "2016-10-10" 84 queryParameters := map[string]interface{}{ 85 "api-version": APIVersion, 86 } 87 88 preparer := autorest.CreatePreparer( 89 autorest.AsContentType("application/json; charset=utf-8"), 90 autorest.AsPost(), 91 autorest.WithBaseURL(client.BaseURI), 92 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/configuration/deploy", pathParameters), 93 autorest.WithJSON(parameters), 94 autorest.WithQueryParameters(queryParameters)) 95 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 96} 97 98// DeploySender sends the Deploy request. The method will close the 99// http.Response Body if it receives an error. 100func (client TenantConfigurationClient) DeploySender(req *http.Request) (future TenantConfigurationDeployFuture, err error) { 101 var resp *http.Response 102 resp, err = autorest.SendWithSender(client, req, 103 azure.DoRetryWithRegistration(client.Client)) 104 if err != nil { 105 return 106 } 107 err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK)) 108 if err != nil { 109 return 110 } 111 future.Future, err = azure.NewFutureFromResponse(resp) 112 return 113} 114 115// DeployResponder handles the response to the Deploy request. The method always 116// closes the http.Response Body. 117func (client TenantConfigurationClient) DeployResponder(resp *http.Response) (result OperationResultContract, err error) { 118 err = autorest.Respond( 119 resp, 120 client.ByInspecting(), 121 azure.WithErrorUnlessStatusCode(http.StatusOK), 122 autorest.ByUnmarshallingJSON(&result), 123 autorest.ByClosing()) 124 result.Response = autorest.Response{Response: resp} 125 return 126} 127 128// Save this operation creates a commit with the current configuration snapshot to the specified branch in the 129// repository. This is a long running operation and could take several minutes to complete. 130// Parameters: 131// resourceGroupName - the name of the resource group. 132// serviceName - the name of the API Management service. 133// parameters - save Configuration parameters. 134func (client TenantConfigurationClient) Save(ctx context.Context, resourceGroupName string, serviceName string, parameters SaveConfigurationParameter) (result TenantConfigurationSaveFuture, err error) { 135 if err := validation.Validate([]validation.Validation{ 136 {TargetValue: serviceName, 137 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 138 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 139 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 140 {TargetValue: parameters, 141 Constraints: []validation.Constraint{{Target: "parameters.Branch", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 142 return result, validation.NewError("apimanagement.TenantConfigurationClient", "Save", err.Error()) 143 } 144 145 req, err := client.SavePreparer(ctx, resourceGroupName, serviceName, parameters) 146 if err != nil { 147 err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Save", nil, "Failure preparing request") 148 return 149 } 150 151 result, err = client.SaveSender(req) 152 if err != nil { 153 err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Save", result.Response(), "Failure sending request") 154 return 155 } 156 157 return 158} 159 160// SavePreparer prepares the Save request. 161func (client TenantConfigurationClient) SavePreparer(ctx context.Context, resourceGroupName string, serviceName string, parameters SaveConfigurationParameter) (*http.Request, error) { 162 pathParameters := map[string]interface{}{ 163 "resourceGroupName": autorest.Encode("path", resourceGroupName), 164 "serviceName": autorest.Encode("path", serviceName), 165 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 166 } 167 168 const APIVersion = "2016-10-10" 169 queryParameters := map[string]interface{}{ 170 "api-version": APIVersion, 171 } 172 173 preparer := autorest.CreatePreparer( 174 autorest.AsContentType("application/json; charset=utf-8"), 175 autorest.AsPost(), 176 autorest.WithBaseURL(client.BaseURI), 177 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/configuration/save", pathParameters), 178 autorest.WithJSON(parameters), 179 autorest.WithQueryParameters(queryParameters)) 180 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 181} 182 183// SaveSender sends the Save request. The method will close the 184// http.Response Body if it receives an error. 185func (client TenantConfigurationClient) SaveSender(req *http.Request) (future TenantConfigurationSaveFuture, err error) { 186 var resp *http.Response 187 resp, err = autorest.SendWithSender(client, req, 188 azure.DoRetryWithRegistration(client.Client)) 189 if err != nil { 190 return 191 } 192 err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK)) 193 if err != nil { 194 return 195 } 196 future.Future, err = azure.NewFutureFromResponse(resp) 197 return 198} 199 200// SaveResponder handles the response to the Save request. The method always 201// closes the http.Response Body. 202func (client TenantConfigurationClient) SaveResponder(resp *http.Response) (result OperationResultContract, err error) { 203 err = autorest.Respond( 204 resp, 205 client.ByInspecting(), 206 azure.WithErrorUnlessStatusCode(http.StatusOK), 207 autorest.ByUnmarshallingJSON(&result), 208 autorest.ByClosing()) 209 result.Response = autorest.Response{Response: resp} 210 return 211} 212 213// Validate this operation validates the changes in the specified Git branch. This is a long running operation and 214// could take several minutes to complete. 215// Parameters: 216// resourceGroupName - the name of the resource group. 217// serviceName - the name of the API Management service. 218// parameters - validate Configuration parameters. 219func (client TenantConfigurationClient) Validate(ctx context.Context, resourceGroupName string, serviceName string, parameters DeployConfigurationParameters) (result TenantConfigurationValidateFuture, err error) { 220 if err := validation.Validate([]validation.Validation{ 221 {TargetValue: serviceName, 222 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 223 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 224 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 225 {TargetValue: parameters, 226 Constraints: []validation.Constraint{{Target: "parameters.Branch", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 227 return result, validation.NewError("apimanagement.TenantConfigurationClient", "Validate", err.Error()) 228 } 229 230 req, err := client.ValidatePreparer(ctx, resourceGroupName, serviceName, parameters) 231 if err != nil { 232 err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Validate", nil, "Failure preparing request") 233 return 234 } 235 236 result, err = client.ValidateSender(req) 237 if err != nil { 238 err = autorest.NewErrorWithError(err, "apimanagement.TenantConfigurationClient", "Validate", result.Response(), "Failure sending request") 239 return 240 } 241 242 return 243} 244 245// ValidatePreparer prepares the Validate request. 246func (client TenantConfigurationClient) ValidatePreparer(ctx context.Context, resourceGroupName string, serviceName string, parameters DeployConfigurationParameters) (*http.Request, error) { 247 pathParameters := map[string]interface{}{ 248 "resourceGroupName": autorest.Encode("path", resourceGroupName), 249 "serviceName": autorest.Encode("path", serviceName), 250 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 251 } 252 253 const APIVersion = "2016-10-10" 254 queryParameters := map[string]interface{}{ 255 "api-version": APIVersion, 256 } 257 258 preparer := autorest.CreatePreparer( 259 autorest.AsContentType("application/json; charset=utf-8"), 260 autorest.AsPost(), 261 autorest.WithBaseURL(client.BaseURI), 262 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/tenant/configuration/validate", pathParameters), 263 autorest.WithJSON(parameters), 264 autorest.WithQueryParameters(queryParameters)) 265 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 266} 267 268// ValidateSender sends the Validate request. The method will close the 269// http.Response Body if it receives an error. 270func (client TenantConfigurationClient) ValidateSender(req *http.Request) (future TenantConfigurationValidateFuture, err error) { 271 var resp *http.Response 272 resp, err = autorest.SendWithSender(client, req, 273 azure.DoRetryWithRegistration(client.Client)) 274 if err != nil { 275 return 276 } 277 err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK)) 278 if err != nil { 279 return 280 } 281 future.Future, err = azure.NewFutureFromResponse(resp) 282 return 283} 284 285// ValidateResponder handles the response to the Validate request. The method always 286// closes the http.Response Body. 287func (client TenantConfigurationClient) ValidateResponder(resp *http.Response) (result OperationResultContract, err error) { 288 err = autorest.Respond( 289 resp, 290 client.ByInspecting(), 291 azure.WithErrorUnlessStatusCode(http.StatusOK), 292 autorest.ByUnmarshallingJSON(&result), 293 autorest.ByClosing()) 294 result.Response = autorest.Response{Response: resp} 295 return 296} 297