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