1// Package cdn implements the Azure ARM Cdn service API version 2017-10-12. 2// 3// Cdn Management Client 4package cdn 5 6// Copyright (c) Microsoft Corporation. All rights reserved. 7// Licensed under the MIT License. See License.txt in the project root for license information. 8// 9// Code generated by Microsoft (R) AutoRest Code Generator. 10// Changes may cause incorrect behavior and will be lost if the code is regenerated. 11 12import ( 13 "context" 14 "github.com/Azure/go-autorest/autorest" 15 "github.com/Azure/go-autorest/autorest/azure" 16 "github.com/Azure/go-autorest/autorest/validation" 17 "github.com/Azure/go-autorest/tracing" 18 "net/http" 19) 20 21const ( 22 // DefaultBaseURI is the default URI used for the service Cdn 23 DefaultBaseURI = "https://management.azure.com" 24) 25 26// BaseClient is the base client for Cdn. 27type BaseClient struct { 28 autorest.Client 29 BaseURI string 30 SubscriptionID string 31} 32 33// New creates an instance of the BaseClient client. 34func New(subscriptionID string) BaseClient { 35 return NewWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint. Use this when interacting with 39// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 40func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { 41 return BaseClient{ 42 Client: autorest.NewClientWithUserAgent(UserAgent()), 43 BaseURI: baseURI, 44 SubscriptionID: subscriptionID, 45 } 46} 47 48// CheckNameAvailability check the availability of a resource name. This is needed for resources where name is globally 49// unique, such as a CDN endpoint. 50// Parameters: 51// checkNameAvailabilityInput - input to check. 52func (client BaseClient) CheckNameAvailability(ctx context.Context, checkNameAvailabilityInput CheckNameAvailabilityInput) (result CheckNameAvailabilityOutput, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.CheckNameAvailability") 55 defer func() { 56 sc := -1 57 if result.Response.Response != nil { 58 sc = result.Response.Response.StatusCode 59 } 60 tracing.EndSpan(ctx, sc, err) 61 }() 62 } 63 if err := validation.Validate([]validation.Validation{ 64 {TargetValue: checkNameAvailabilityInput, 65 Constraints: []validation.Constraint{{Target: "checkNameAvailabilityInput.Name", Name: validation.Null, Rule: true, Chain: nil}, 66 {Target: "checkNameAvailabilityInput.Type", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 67 return result, validation.NewError("cdn.BaseClient", "CheckNameAvailability", err.Error()) 68 } 69 70 req, err := client.CheckNameAvailabilityPreparer(ctx, checkNameAvailabilityInput) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "cdn.BaseClient", "CheckNameAvailability", nil, "Failure preparing request") 73 return 74 } 75 76 resp, err := client.CheckNameAvailabilitySender(req) 77 if err != nil { 78 result.Response = autorest.Response{Response: resp} 79 err = autorest.NewErrorWithError(err, "cdn.BaseClient", "CheckNameAvailability", resp, "Failure sending request") 80 return 81 } 82 83 result, err = client.CheckNameAvailabilityResponder(resp) 84 if err != nil { 85 err = autorest.NewErrorWithError(err, "cdn.BaseClient", "CheckNameAvailability", resp, "Failure responding to request") 86 return 87 } 88 89 return 90} 91 92// CheckNameAvailabilityPreparer prepares the CheckNameAvailability request. 93func (client BaseClient) CheckNameAvailabilityPreparer(ctx context.Context, checkNameAvailabilityInput CheckNameAvailabilityInput) (*http.Request, error) { 94 const APIVersion = "2017-10-12" 95 queryParameters := map[string]interface{}{ 96 "api-version": APIVersion, 97 } 98 99 preparer := autorest.CreatePreparer( 100 autorest.AsContentType("application/json; charset=utf-8"), 101 autorest.AsPost(), 102 autorest.WithBaseURL(client.BaseURI), 103 autorest.WithPath("/providers/Microsoft.Cdn/checkNameAvailability"), 104 autorest.WithJSON(checkNameAvailabilityInput), 105 autorest.WithQueryParameters(queryParameters)) 106 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 107} 108 109// CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the 110// http.Response Body if it receives an error. 111func (client BaseClient) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) { 112 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 113} 114 115// CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always 116// closes the http.Response Body. 117func (client BaseClient) CheckNameAvailabilityResponder(resp *http.Response) (result CheckNameAvailabilityOutput, err error) { 118 err = autorest.Respond( 119 resp, 120 azure.WithErrorUnlessStatusCode(http.StatusOK), 121 autorest.ByUnmarshallingJSON(&result), 122 autorest.ByClosing()) 123 result.Response = autorest.Response{Response: resp} 124 return 125} 126 127// CheckNameAvailabilityWithSubscription check the availability of a resource name. This is needed for resources where 128// name is globally unique, such as a CDN endpoint. 129// Parameters: 130// checkNameAvailabilityInput - input to check. 131func (client BaseClient) CheckNameAvailabilityWithSubscription(ctx context.Context, checkNameAvailabilityInput CheckNameAvailabilityInput) (result CheckNameAvailabilityOutput, err error) { 132 if tracing.IsEnabled() { 133 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.CheckNameAvailabilityWithSubscription") 134 defer func() { 135 sc := -1 136 if result.Response.Response != nil { 137 sc = result.Response.Response.StatusCode 138 } 139 tracing.EndSpan(ctx, sc, err) 140 }() 141 } 142 if err := validation.Validate([]validation.Validation{ 143 {TargetValue: checkNameAvailabilityInput, 144 Constraints: []validation.Constraint{{Target: "checkNameAvailabilityInput.Name", Name: validation.Null, Rule: true, Chain: nil}, 145 {Target: "checkNameAvailabilityInput.Type", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 146 return result, validation.NewError("cdn.BaseClient", "CheckNameAvailabilityWithSubscription", err.Error()) 147 } 148 149 req, err := client.CheckNameAvailabilityWithSubscriptionPreparer(ctx, checkNameAvailabilityInput) 150 if err != nil { 151 err = autorest.NewErrorWithError(err, "cdn.BaseClient", "CheckNameAvailabilityWithSubscription", nil, "Failure preparing request") 152 return 153 } 154 155 resp, err := client.CheckNameAvailabilityWithSubscriptionSender(req) 156 if err != nil { 157 result.Response = autorest.Response{Response: resp} 158 err = autorest.NewErrorWithError(err, "cdn.BaseClient", "CheckNameAvailabilityWithSubscription", resp, "Failure sending request") 159 return 160 } 161 162 result, err = client.CheckNameAvailabilityWithSubscriptionResponder(resp) 163 if err != nil { 164 err = autorest.NewErrorWithError(err, "cdn.BaseClient", "CheckNameAvailabilityWithSubscription", resp, "Failure responding to request") 165 return 166 } 167 168 return 169} 170 171// CheckNameAvailabilityWithSubscriptionPreparer prepares the CheckNameAvailabilityWithSubscription request. 172func (client BaseClient) CheckNameAvailabilityWithSubscriptionPreparer(ctx context.Context, checkNameAvailabilityInput CheckNameAvailabilityInput) (*http.Request, error) { 173 pathParameters := map[string]interface{}{ 174 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 175 } 176 177 const APIVersion = "2017-10-12" 178 queryParameters := map[string]interface{}{ 179 "api-version": APIVersion, 180 } 181 182 preparer := autorest.CreatePreparer( 183 autorest.AsContentType("application/json; charset=utf-8"), 184 autorest.AsPost(), 185 autorest.WithBaseURL(client.BaseURI), 186 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Cdn/checkNameAvailability", pathParameters), 187 autorest.WithJSON(checkNameAvailabilityInput), 188 autorest.WithQueryParameters(queryParameters)) 189 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 190} 191 192// CheckNameAvailabilityWithSubscriptionSender sends the CheckNameAvailabilityWithSubscription request. The method will close the 193// http.Response Body if it receives an error. 194func (client BaseClient) CheckNameAvailabilityWithSubscriptionSender(req *http.Request) (*http.Response, error) { 195 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 196} 197 198// CheckNameAvailabilityWithSubscriptionResponder handles the response to the CheckNameAvailabilityWithSubscription request. The method always 199// closes the http.Response Body. 200func (client BaseClient) CheckNameAvailabilityWithSubscriptionResponder(resp *http.Response) (result CheckNameAvailabilityOutput, err error) { 201 err = autorest.Respond( 202 resp, 203 azure.WithErrorUnlessStatusCode(http.StatusOK), 204 autorest.ByUnmarshallingJSON(&result), 205 autorest.ByClosing()) 206 result.Response = autorest.Response{Response: resp} 207 return 208} 209 210// ValidateProbe check if the probe path is a valid path and the file can be accessed. Probe path is the path to a file 211// hosted on the origin server to help accelerate the delivery of dynamic content via the CDN endpoint. This path is 212// relative to the origin path specified in the endpoint configuration. 213// Parameters: 214// validateProbeInput - input to check. 215func (client BaseClient) ValidateProbe(ctx context.Context, validateProbeInput ValidateProbeInput) (result ValidateProbeOutput, err error) { 216 if tracing.IsEnabled() { 217 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.ValidateProbe") 218 defer func() { 219 sc := -1 220 if result.Response.Response != nil { 221 sc = result.Response.Response.StatusCode 222 } 223 tracing.EndSpan(ctx, sc, err) 224 }() 225 } 226 if err := validation.Validate([]validation.Validation{ 227 {TargetValue: validateProbeInput, 228 Constraints: []validation.Constraint{{Target: "validateProbeInput.ProbeURL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 229 return result, validation.NewError("cdn.BaseClient", "ValidateProbe", err.Error()) 230 } 231 232 req, err := client.ValidateProbePreparer(ctx, validateProbeInput) 233 if err != nil { 234 err = autorest.NewErrorWithError(err, "cdn.BaseClient", "ValidateProbe", nil, "Failure preparing request") 235 return 236 } 237 238 resp, err := client.ValidateProbeSender(req) 239 if err != nil { 240 result.Response = autorest.Response{Response: resp} 241 err = autorest.NewErrorWithError(err, "cdn.BaseClient", "ValidateProbe", resp, "Failure sending request") 242 return 243 } 244 245 result, err = client.ValidateProbeResponder(resp) 246 if err != nil { 247 err = autorest.NewErrorWithError(err, "cdn.BaseClient", "ValidateProbe", resp, "Failure responding to request") 248 return 249 } 250 251 return 252} 253 254// ValidateProbePreparer prepares the ValidateProbe request. 255func (client BaseClient) ValidateProbePreparer(ctx context.Context, validateProbeInput ValidateProbeInput) (*http.Request, error) { 256 pathParameters := map[string]interface{}{ 257 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 258 } 259 260 const APIVersion = "2017-10-12" 261 queryParameters := map[string]interface{}{ 262 "api-version": APIVersion, 263 } 264 265 preparer := autorest.CreatePreparer( 266 autorest.AsContentType("application/json; charset=utf-8"), 267 autorest.AsPost(), 268 autorest.WithBaseURL(client.BaseURI), 269 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Cdn/validateProbe", pathParameters), 270 autorest.WithJSON(validateProbeInput), 271 autorest.WithQueryParameters(queryParameters)) 272 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 273} 274 275// ValidateProbeSender sends the ValidateProbe request. The method will close the 276// http.Response Body if it receives an error. 277func (client BaseClient) ValidateProbeSender(req *http.Request) (*http.Response, error) { 278 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 279} 280 281// ValidateProbeResponder handles the response to the ValidateProbe request. The method always 282// closes the http.Response Body. 283func (client BaseClient) ValidateProbeResponder(resp *http.Response) (result ValidateProbeOutput, err error) { 284 err = autorest.Respond( 285 resp, 286 azure.WithErrorUnlessStatusCode(http.StatusOK), 287 autorest.ByUnmarshallingJSON(&result), 288 autorest.ByClosing()) 289 result.Response = autorest.Response{Response: resp} 290 return 291} 292