1package apimanagement 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// NetworkStatusClient is the apiManagement Client 19type NetworkStatusClient struct { 20 BaseClient 21} 22 23// NewNetworkStatusClient creates an instance of the NetworkStatusClient client. 24func NewNetworkStatusClient(subscriptionID string) NetworkStatusClient { 25 return NewNetworkStatusClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewNetworkStatusClientWithBaseURI creates an instance of the NetworkStatusClient client using a custom endpoint. 29// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewNetworkStatusClientWithBaseURI(baseURI string, subscriptionID string) NetworkStatusClient { 31 return NetworkStatusClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// ListByLocation gets the Connectivity Status to the external resources on which the Api Management service depends 35// from inside the Cloud Service. This also returns the DNS Servers as visible to the CloudService. 36// Parameters: 37// resourceGroupName - the name of the resource group. 38// serviceName - the name of the API Management service. 39// locationName - location in which the API Management service is deployed. This is one of the Azure Regions 40// like West US, East US, South Central US. 41func (client NetworkStatusClient) ListByLocation(ctx context.Context, resourceGroupName string, serviceName string, locationName string) (result NetworkStatusContract, err error) { 42 if tracing.IsEnabled() { 43 ctx = tracing.StartSpan(ctx, fqdn+"/NetworkStatusClient.ListByLocation") 44 defer func() { 45 sc := -1 46 if result.Response.Response != nil { 47 sc = result.Response.Response.StatusCode 48 } 49 tracing.EndSpan(ctx, sc, err) 50 }() 51 } 52 if err := validation.Validate([]validation.Validation{ 53 {TargetValue: serviceName, 54 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 55 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 56 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}, 57 {TargetValue: locationName, 58 Constraints: []validation.Constraint{{Target: "locationName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 59 return result, validation.NewError("apimanagement.NetworkStatusClient", "ListByLocation", err.Error()) 60 } 61 62 req, err := client.ListByLocationPreparer(ctx, resourceGroupName, serviceName, locationName) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "apimanagement.NetworkStatusClient", "ListByLocation", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.ListByLocationSender(req) 69 if err != nil { 70 result.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "apimanagement.NetworkStatusClient", "ListByLocation", resp, "Failure sending request") 72 return 73 } 74 75 result, err = client.ListByLocationResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "apimanagement.NetworkStatusClient", "ListByLocation", resp, "Failure responding to request") 78 return 79 } 80 81 return 82} 83 84// ListByLocationPreparer prepares the ListByLocation request. 85func (client NetworkStatusClient) ListByLocationPreparer(ctx context.Context, resourceGroupName string, serviceName string, locationName string) (*http.Request, error) { 86 pathParameters := map[string]interface{}{ 87 "locationName": autorest.Encode("path", locationName), 88 "resourceGroupName": autorest.Encode("path", resourceGroupName), 89 "serviceName": autorest.Encode("path", serviceName), 90 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 91 } 92 93 const APIVersion = "2021-01-01-preview" 94 queryParameters := map[string]interface{}{ 95 "api-version": APIVersion, 96 } 97 98 preparer := autorest.CreatePreparer( 99 autorest.AsGet(), 100 autorest.WithBaseURL(client.BaseURI), 101 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/locations/{locationName}/networkstatus", pathParameters), 102 autorest.WithQueryParameters(queryParameters)) 103 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 104} 105 106// ListByLocationSender sends the ListByLocation request. The method will close the 107// http.Response Body if it receives an error. 108func (client NetworkStatusClient) ListByLocationSender(req *http.Request) (*http.Response, error) { 109 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 110} 111 112// ListByLocationResponder handles the response to the ListByLocation request. The method always 113// closes the http.Response Body. 114func (client NetworkStatusClient) ListByLocationResponder(resp *http.Response) (result NetworkStatusContract, err error) { 115 err = autorest.Respond( 116 resp, 117 azure.WithErrorUnlessStatusCode(http.StatusOK), 118 autorest.ByUnmarshallingJSON(&result), 119 autorest.ByClosing()) 120 result.Response = autorest.Response{Response: resp} 121 return 122} 123 124// ListByService gets the Connectivity Status to the external resources on which the Api Management service depends 125// from inside the Cloud Service. This also returns the DNS Servers as visible to the CloudService. 126// Parameters: 127// resourceGroupName - the name of the resource group. 128// serviceName - the name of the API Management service. 129func (client NetworkStatusClient) ListByService(ctx context.Context, resourceGroupName string, serviceName string) (result ListNetworkStatusContractByLocation, err error) { 130 if tracing.IsEnabled() { 131 ctx = tracing.StartSpan(ctx, fqdn+"/NetworkStatusClient.ListByService") 132 defer func() { 133 sc := -1 134 if result.Response.Response != nil { 135 sc = result.Response.Response.StatusCode 136 } 137 tracing.EndSpan(ctx, sc, err) 138 }() 139 } 140 if err := validation.Validate([]validation.Validation{ 141 {TargetValue: serviceName, 142 Constraints: []validation.Constraint{{Target: "serviceName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 143 {Target: "serviceName", Name: validation.MinLength, Rule: 1, Chain: nil}, 144 {Target: "serviceName", Name: validation.Pattern, Rule: `^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$`, Chain: nil}}}}); err != nil { 145 return result, validation.NewError("apimanagement.NetworkStatusClient", "ListByService", err.Error()) 146 } 147 148 req, err := client.ListByServicePreparer(ctx, resourceGroupName, serviceName) 149 if err != nil { 150 err = autorest.NewErrorWithError(err, "apimanagement.NetworkStatusClient", "ListByService", nil, "Failure preparing request") 151 return 152 } 153 154 resp, err := client.ListByServiceSender(req) 155 if err != nil { 156 result.Response = autorest.Response{Response: resp} 157 err = autorest.NewErrorWithError(err, "apimanagement.NetworkStatusClient", "ListByService", resp, "Failure sending request") 158 return 159 } 160 161 result, err = client.ListByServiceResponder(resp) 162 if err != nil { 163 err = autorest.NewErrorWithError(err, "apimanagement.NetworkStatusClient", "ListByService", resp, "Failure responding to request") 164 return 165 } 166 167 return 168} 169 170// ListByServicePreparer prepares the ListByService request. 171func (client NetworkStatusClient) ListByServicePreparer(ctx context.Context, resourceGroupName string, serviceName string) (*http.Request, error) { 172 pathParameters := map[string]interface{}{ 173 "resourceGroupName": autorest.Encode("path", resourceGroupName), 174 "serviceName": autorest.Encode("path", serviceName), 175 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 176 } 177 178 const APIVersion = "2021-01-01-preview" 179 queryParameters := map[string]interface{}{ 180 "api-version": APIVersion, 181 } 182 183 preparer := autorest.CreatePreparer( 184 autorest.AsGet(), 185 autorest.WithBaseURL(client.BaseURI), 186 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/networkstatus", pathParameters), 187 autorest.WithQueryParameters(queryParameters)) 188 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 189} 190 191// ListByServiceSender sends the ListByService request. The method will close the 192// http.Response Body if it receives an error. 193func (client NetworkStatusClient) ListByServiceSender(req *http.Request) (*http.Response, error) { 194 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 195} 196 197// ListByServiceResponder handles the response to the ListByService request. The method always 198// closes the http.Response Body. 199func (client NetworkStatusClient) ListByServiceResponder(resp *http.Response) (result ListNetworkStatusContractByLocation, err error) { 200 err = autorest.Respond( 201 resp, 202 azure.WithErrorUnlessStatusCode(http.StatusOK), 203 autorest.ByUnmarshallingJSON(&result.Value), 204 autorest.ByClosing()) 205 result.Response = autorest.Response{Response: resp} 206 return 207} 208