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