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// NetworkStatusClient is the apiManagement Client 30type NetworkStatusClient struct { 31 BaseClient 32} 33 34// NewNetworkStatusClient creates an instance of the NetworkStatusClient client. 35func NewNetworkStatusClient(subscriptionID string) NetworkStatusClient { 36 return NewNetworkStatusClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewNetworkStatusClientWithBaseURI creates an instance of the NetworkStatusClient client. 40func NewNetworkStatusClientWithBaseURI(baseURI string, subscriptionID string) NetworkStatusClient { 41 return NetworkStatusClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// ListByLocation gets the Connectivity Status to the external resources on which the Api Management service depends 45// from inside the Cloud Service. This also returns the DNS Servers as visible to the CloudService. 46// Parameters: 47// resourceGroupName - the name of the resource group. 48// serviceName - the name of the API Management service. 49// locationName - location in which the API Management service is deployed. This is one of the Azure Regions 50// like West US, East US, South Central US. 51func (client NetworkStatusClient) ListByLocation(ctx context.Context, resourceGroupName string, serviceName string, locationName string) (result NetworkStatusContract, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/NetworkStatusClient.ListByLocation") 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}}}, 67 {TargetValue: locationName, 68 Constraints: []validation.Constraint{{Target: "locationName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 69 return result, validation.NewError("apimanagement.NetworkStatusClient", "ListByLocation", err.Error()) 70 } 71 72 req, err := client.ListByLocationPreparer(ctx, resourceGroupName, serviceName, locationName) 73 if err != nil { 74 err = autorest.NewErrorWithError(err, "apimanagement.NetworkStatusClient", "ListByLocation", nil, "Failure preparing request") 75 return 76 } 77 78 resp, err := client.ListByLocationSender(req) 79 if err != nil { 80 result.Response = autorest.Response{Response: resp} 81 err = autorest.NewErrorWithError(err, "apimanagement.NetworkStatusClient", "ListByLocation", resp, "Failure sending request") 82 return 83 } 84 85 result, err = client.ListByLocationResponder(resp) 86 if err != nil { 87 err = autorest.NewErrorWithError(err, "apimanagement.NetworkStatusClient", "ListByLocation", resp, "Failure responding to request") 88 } 89 90 return 91} 92 93// ListByLocationPreparer prepares the ListByLocation request. 94func (client NetworkStatusClient) ListByLocationPreparer(ctx context.Context, resourceGroupName string, serviceName string, locationName string) (*http.Request, error) { 95 pathParameters := map[string]interface{}{ 96 "locationName": autorest.Encode("path", locationName), 97 "resourceGroupName": autorest.Encode("path", resourceGroupName), 98 "serviceName": autorest.Encode("path", serviceName), 99 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 100 } 101 102 const APIVersion = "2019-01-01" 103 queryParameters := map[string]interface{}{ 104 "api-version": APIVersion, 105 } 106 107 preparer := autorest.CreatePreparer( 108 autorest.AsGet(), 109 autorest.WithBaseURL(client.BaseURI), 110 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/locations/{locationName}/networkstatus", pathParameters), 111 autorest.WithQueryParameters(queryParameters)) 112 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 113} 114 115// ListByLocationSender sends the ListByLocation request. The method will close the 116// http.Response Body if it receives an error. 117func (client NetworkStatusClient) ListByLocationSender(req *http.Request) (*http.Response, error) { 118 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 119 return autorest.SendWithSender(client, req, sd...) 120} 121 122// ListByLocationResponder handles the response to the ListByLocation request. The method always 123// closes the http.Response Body. 124func (client NetworkStatusClient) ListByLocationResponder(resp *http.Response) (result NetworkStatusContract, err error) { 125 err = autorest.Respond( 126 resp, 127 client.ByInspecting(), 128 azure.WithErrorUnlessStatusCode(http.StatusOK), 129 autorest.ByUnmarshallingJSON(&result), 130 autorest.ByClosing()) 131 result.Response = autorest.Response{Response: resp} 132 return 133} 134 135// ListByService gets the Connectivity Status to the external resources on which the Api Management service depends 136// from inside the Cloud Service. This also returns the DNS Servers as visible to the CloudService. 137// Parameters: 138// resourceGroupName - the name of the resource group. 139// serviceName - the name of the API Management service. 140func (client NetworkStatusClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string) (result ListNetworkStatusContractByLocation, err error) { 141 if tracing.IsEnabled() { 142 ctx = tracing.StartSpan(ctx, fqdn+"/NetworkStatusClient.ListByService") 143 defer func() { 144 sc := -1 145 if result.Response.Response != nil { 146 sc = result.Response.Response.StatusCode 147 } 148 tracing.EndSpan(ctx, sc, err) 149 }() 150 } 151 if err := validation.Validate([]validation.Validation{ 152 {TargetValue: serviceName, 153 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 154 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 155 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 156 return result, validation.NewError("apimanagement.NetworkStatusClient", "ListByService", err.Error()) 157 } 158 159 req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName) 160 if err != nil { 161 err = autorest.NewErrorWithError(err, "apimanagement.NetworkStatusClient", "ListByService", nil, "Failure preparing request") 162 return 163 } 164 165 resp, err := client.ListByServiceSender(req) 166 if err != nil { 167 result.Response = autorest.Response{Response: resp} 168 err = autorest.NewErrorWithError(err, "apimanagement.NetworkStatusClient", "ListByService", resp, "Failure sending request") 169 return 170 } 171 172 result, err = client.ListByServiceResponder(resp) 173 if err != nil { 174 err = autorest.NewErrorWithError(err, "apimanagement.NetworkStatusClient", "ListByService", resp, "Failure responding to request") 175 } 176 177 return 178} 179 180// ListByServicePreparer prepares the ListByService request. 181func (client NetworkStatusClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) { 182 pathParameters := map[string]interface{}{ 183 "resourceGroupName": autorest.Encode("path", resourceGroupName), 184 "serviceName": autorest.Encode("path", serviceName), 185 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 186 } 187 188 const APIVersion = "2019-01-01" 189 queryParameters := map[string]interface{}{ 190 "api-version": APIVersion, 191 } 192 193 preparer := autorest.CreatePreparer( 194 autorest.AsGet(), 195 autorest.WithBaseURL(client.BaseURI), 196 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/networkstatus", pathParameters), 197 autorest.WithQueryParameters(queryParameters)) 198 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 199} 200 201// ListByServiceSender sends the ListByService request. The method will close the 202// http.Response Body if it receives an error. 203func (client NetworkStatusClient) ListByServiceSender(req *http.Request) (*http.Response, error) { 204 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 205 return autorest.SendWithSender(client, req, sd...) 206} 207 208// ListByServiceResponder handles the response to the ListByService request. The method always 209// closes the http.Response Body. 210func (client NetworkStatusClient) ListByServiceResponder(resp *http.Response) (result ListNetworkStatusContractByLocation, err error) { 211 err = autorest.Respond( 212 resp, 213 client.ByInspecting(), 214 azure.WithErrorUnlessStatusCode(http.StatusOK), 215 autorest.ByUnmarshallingJSON(&result.Value), 216 autorest.ByClosing()) 217 result.Response = autorest.Response{Response: resp} 218 return 219} 220