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 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// SignUpSettingsClient is the apiManagement Client 30type SignUpSettingsClient struct { 31 BaseClient 32} 33 34// NewSignUpSettingsClient creates an instance of the SignUpSettingsClient client. 35func NewSignUpSettingsClient(subscriptionID string) SignUpSettingsClient { 36 return NewSignUpSettingsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewSignUpSettingsClientWithBaseURI creates an instance of the SignUpSettingsClient client using a custom endpoint. 40// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewSignUpSettingsClientWithBaseURI(baseURI string, subscriptionID string) SignUpSettingsClient { 42 return SignUpSettingsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// CreateOrUpdate create or Update Sign-Up settings. 46// Parameters: 47// resourceGroupName - the name of the resource group. 48// serviceName - the name of the API Management service. 49// parameters - create or update parameters. 50func (client SignUpSettingsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serviceName string, parameters PortalSignupSettings) (result PortalSignupSettings, err error) { 51 if tracing.IsEnabled() { 52 ctx = tracing.StartSpan(ctx, fqdn+"/SignUpSettingsClient.CreateOrUpdate") 53 defer func() { 54 sc := -1 55 if result.Response.Response != nil { 56 sc = result.Response.Response.StatusCode 57 } 58 tracing.EndSpan(ctx, sc, err) 59 }() 60 } 61 if err := validation.Validate([]validation.Validation{ 62 {TargetValue: serviceName, 63 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 64 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 65 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 66 return result, validation.NewError("apimanagement.SignUpSettingsClient", "CreateOrUpdate", err.Error()) 67 } 68 69 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serviceName, parameters) 70 if err != nil { 71 err = autorest.NewErrorWithError(err, "apimanagement.SignUpSettingsClient", "CreateOrUpdate", nil, "Failure preparing request") 72 return 73 } 74 75 resp, err := client.CreateOrUpdateSender(req) 76 if err != nil { 77 result.Response = autorest.Response{Response: resp} 78 err = autorest.NewErrorWithError(err, "apimanagement.SignUpSettingsClient", "CreateOrUpdate", resp, "Failure sending request") 79 return 80 } 81 82 result, err = client.CreateOrUpdateResponder(resp) 83 if err != nil { 84 err = autorest.NewErrorWithError(err, "apimanagement.SignUpSettingsClient", "CreateOrUpdate", resp, "Failure responding to request") 85 } 86 87 return 88} 89 90// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 91func (client SignUpSettingsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, parameters PortalSignupSettings) (*http.Request, error) { 92 pathParameters := map[string]interface{}{ 93 "resourceGroupName": autorest.Encode("path", resourceGroupName), 94 "serviceName": autorest.Encode("path", serviceName), 95 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 96 } 97 98 const APIVersion = "2018-01-01" 99 queryParameters := map[string]interface{}{ 100 "api-version": APIVersion, 101 } 102 103 preparer := autorest.CreatePreparer( 104 autorest.AsContentType("application/json; charset=utf-8"), 105 autorest.AsPut(), 106 autorest.WithBaseURL(client.BaseURI), 107 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/portalsettings/signup", pathParameters), 108 autorest.WithJSON(parameters), 109 autorest.WithQueryParameters(queryParameters)) 110 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 111} 112 113// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 114// http.Response Body if it receives an error. 115func (client SignUpSettingsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 116 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 117} 118 119// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 120// closes the http.Response Body. 121func (client SignUpSettingsClient) CreateOrUpdateResponder(resp *http.Response) (result PortalSignupSettings, err error) { 122 err = autorest.Respond( 123 resp, 124 client.ByInspecting(), 125 azure.WithErrorUnlessStatusCode(http.StatusOK), 126 autorest.ByUnmarshallingJSON(&result), 127 autorest.ByClosing()) 128 result.Response = autorest.Response{Response: resp} 129 return 130} 131 132// Get get Sign-Up settings. 133// Parameters: 134// resourceGroupName - the name of the resource group. 135// serviceName - the name of the API Management service. 136func (client SignUpSettingsClient) Get(ctx context.Context, resourceGroupName string, serviceName string) (result PortalSignupSettings, err error) { 137 if tracing.IsEnabled() { 138 ctx = tracing.StartSpan(ctx, fqdn+"/SignUpSettingsClient.Get") 139 defer func() { 140 sc := -1 141 if result.Response.Response != nil { 142 sc = result.Response.Response.StatusCode 143 } 144 tracing.EndSpan(ctx, sc, err) 145 }() 146 } 147 if err := validation.Validate([]validation.Validation{ 148 {TargetValue: serviceName, 149 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 150 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 151 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 152 return result, validation.NewError("apimanagement.SignUpSettingsClient", "Get", err.Error()) 153 } 154 155 req, err := client.GetPreparer(ctx, resourceGroupName, serviceName) 156 if err != nil { 157 err = autorest.NewErrorWithError(err, "apimanagement.SignUpSettingsClient", "Get", nil, "Failure preparing request") 158 return 159 } 160 161 resp, err := client.GetSender(req) 162 if err != nil { 163 result.Response = autorest.Response{Response: resp} 164 err = autorest.NewErrorWithError(err, "apimanagement.SignUpSettingsClient", "Get", resp, "Failure sending request") 165 return 166 } 167 168 result, err = client.GetResponder(resp) 169 if err != nil { 170 err = autorest.NewErrorWithError(err, "apimanagement.SignUpSettingsClient", "Get", resp, "Failure responding to request") 171 } 172 173 return 174} 175 176// GetPreparer prepares the Get request. 177func (client SignUpSettingsClient) GetPreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) { 178 pathParameters := map[string]interface{}{ 179 "resourceGroupName": autorest.Encode("path", resourceGroupName), 180 "serviceName": autorest.Encode("path", serviceName), 181 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 182 } 183 184 const APIVersion = "2018-01-01" 185 queryParameters := map[string]interface{}{ 186 "api-version": APIVersion, 187 } 188 189 preparer := autorest.CreatePreparer( 190 autorest.AsGet(), 191 autorest.WithBaseURL(client.BaseURI), 192 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/portalsettings/signup", pathParameters), 193 autorest.WithQueryParameters(queryParameters)) 194 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 195} 196 197// GetSender sends the Get request. The method will close the 198// http.Response Body if it receives an error. 199func (client SignUpSettingsClient) GetSender(req *http.Request) (*http.Response, error) { 200 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 201} 202 203// GetResponder handles the response to the Get request. The method always 204// closes the http.Response Body. 205func (client SignUpSettingsClient) GetResponder(resp *http.Response) (result PortalSignupSettings, err error) { 206 err = autorest.Respond( 207 resp, 208 client.ByInspecting(), 209 azure.WithErrorUnlessStatusCode(http.StatusOK), 210 autorest.ByUnmarshallingJSON(&result), 211 autorest.ByClosing()) 212 result.Response = autorest.Response{Response: resp} 213 return 214} 215 216// GetEntityTag gets the entity state (Etag) version of the SignUpSettings. 217// Parameters: 218// resourceGroupName - the name of the resource group. 219// serviceName - the name of the API Management service. 220func (client SignUpSettingsClient) GetEntityTag(ctx context.Context, resourceGroupName string, serviceName string) (result autorest.Response, err error) { 221 if tracing.IsEnabled() { 222 ctx = tracing.StartSpan(ctx, fqdn+"/SignUpSettingsClient.GetEntityTag") 223 defer func() { 224 sc := -1 225 if result.Response != nil { 226 sc = result.Response.StatusCode 227 } 228 tracing.EndSpan(ctx, sc, err) 229 }() 230 } 231 if err := validation.Validate([]validation.Validation{ 232 {TargetValue: serviceName, 233 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 234 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 235 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 236 return result, validation.NewError("apimanagement.SignUpSettingsClient", "GetEntityTag", err.Error()) 237 } 238 239 req, err := client.GetEntityTagPreparer(ctx, resourceGroupName, serviceName) 240 if err != nil { 241 err = autorest.NewErrorWithError(err, "apimanagement.SignUpSettingsClient", "GetEntityTag", nil, "Failure preparing request") 242 return 243 } 244 245 resp, err := client.GetEntityTagSender(req) 246 if err != nil { 247 result.Response = resp 248 err = autorest.NewErrorWithError(err, "apimanagement.SignUpSettingsClient", "GetEntityTag", resp, "Failure sending request") 249 return 250 } 251 252 result, err = client.GetEntityTagResponder(resp) 253 if err != nil { 254 err = autorest.NewErrorWithError(err, "apimanagement.SignUpSettingsClient", "GetEntityTag", resp, "Failure responding to request") 255 } 256 257 return 258} 259 260// GetEntityTagPreparer prepares the GetEntityTag request. 261func (client SignUpSettingsClient) GetEntityTagPreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) { 262 pathParameters := map[string]interface{}{ 263 "resourceGroupName": autorest.Encode("path", resourceGroupName), 264 "serviceName": autorest.Encode("path", serviceName), 265 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 266 } 267 268 const APIVersion = "2018-01-01" 269 queryParameters := map[string]interface{}{ 270 "api-version": APIVersion, 271 } 272 273 preparer := autorest.CreatePreparer( 274 autorest.AsHead(), 275 autorest.WithBaseURL(client.BaseURI), 276 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/portalsettings/signup", pathParameters), 277 autorest.WithQueryParameters(queryParameters)) 278 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 279} 280 281// GetEntityTagSender sends the GetEntityTag request. The method will close the 282// http.Response Body if it receives an error. 283func (client SignUpSettingsClient) GetEntityTagSender(req *http.Request) (*http.Response, error) { 284 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 285} 286 287// GetEntityTagResponder handles the response to the GetEntityTag request. The method always 288// closes the http.Response Body. 289func (client SignUpSettingsClient) GetEntityTagResponder(resp *http.Response) (result autorest.Response, err error) { 290 err = autorest.Respond( 291 resp, 292 client.ByInspecting(), 293 azure.WithErrorUnlessStatusCode(http.StatusOK), 294 autorest.ByClosing()) 295 result.Response = resp 296 return 297} 298 299// Update update Sign-Up settings. 300// Parameters: 301// resourceGroupName - the name of the resource group. 302// serviceName - the name of the API Management service. 303// parameters - update Sign-Up settings. 304// ifMatch - eTag of the Entity. ETag should match the current entity state from the header response of the GET 305// request or it should be * for unconditional update. 306func (client SignUpSettingsClient) Update(ctx context.Context, resourceGroupName string, serviceName string, parameters PortalSignupSettings, ifMatch string) (result autorest.Response, err error) { 307 if tracing.IsEnabled() { 308 ctx = tracing.StartSpan(ctx, fqdn+"/SignUpSettingsClient.Update") 309 defer func() { 310 sc := -1 311 if result.Response != nil { 312 sc = result.Response.StatusCode 313 } 314 tracing.EndSpan(ctx, sc, err) 315 }() 316 } 317 if err := validation.Validate([]validation.Validation{ 318 {TargetValue: serviceName, 319 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 320 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 321 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 322 return result, validation.NewError("apimanagement.SignUpSettingsClient", "Update", err.Error()) 323 } 324 325 req, err := client.UpdatePreparer(ctx, resourceGroupName, serviceName, parameters, ifMatch) 326 if err != nil { 327 err = autorest.NewErrorWithError(err, "apimanagement.SignUpSettingsClient", "Update", nil, "Failure preparing request") 328 return 329 } 330 331 resp, err := client.UpdateSender(req) 332 if err != nil { 333 result.Response = resp 334 err = autorest.NewErrorWithError(err, "apimanagement.SignUpSettingsClient", "Update", resp, "Failure sending request") 335 return 336 } 337 338 result, err = client.UpdateResponder(resp) 339 if err != nil { 340 err = autorest.NewErrorWithError(err, "apimanagement.SignUpSettingsClient", "Update", resp, "Failure responding to request") 341 } 342 343 return 344} 345 346// UpdatePreparer prepares the Update request. 347func (client SignUpSettingsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serviceName string, parameters PortalSignupSettings, ifMatch string) (*http.Request, error) { 348 pathParameters := map[string]interface{}{ 349 "resourceGroupName": autorest.Encode("path", resourceGroupName), 350 "serviceName": autorest.Encode("path", serviceName), 351 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 352 } 353 354 const APIVersion = "2018-01-01" 355 queryParameters := map[string]interface{}{ 356 "api-version": APIVersion, 357 } 358 359 preparer := autorest.CreatePreparer( 360 autorest.AsContentType("application/json; charset=utf-8"), 361 autorest.AsPatch(), 362 autorest.WithBaseURL(client.BaseURI), 363 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/portalsettings/signup", pathParameters), 364 autorest.WithJSON(parameters), 365 autorest.WithQueryParameters(queryParameters), 366 autorest.WithHeader("If-Match", autorest.String(ifMatch))) 367 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 368} 369 370// UpdateSender sends the Update request. The method will close the 371// http.Response Body if it receives an error. 372func (client SignUpSettingsClient) UpdateSender(req *http.Request) (*http.Response, error) { 373 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 374} 375 376// UpdateResponder handles the response to the Update request. The method always 377// closes the http.Response Body. 378func (client SignUpSettingsClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { 379 err = autorest.Respond( 380 resp, 381 client.ByInspecting(), 382 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 383 autorest.ByClosing()) 384 result.Response = resp 385 return 386} 387