1package network 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/tracing" 14 "net/http" 15) 16 17// VpnSiteLinksClient is the network Client 18type VpnSiteLinksClient struct { 19 BaseClient 20} 21 22// NewVpnSiteLinksClient creates an instance of the VpnSiteLinksClient client. 23func NewVpnSiteLinksClient(subscriptionID string) VpnSiteLinksClient { 24 return NewVpnSiteLinksClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewVpnSiteLinksClientWithBaseURI creates an instance of the VpnSiteLinksClient client using a custom endpoint. Use 28// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 29func NewVpnSiteLinksClientWithBaseURI(baseURI string, subscriptionID string) VpnSiteLinksClient { 30 return VpnSiteLinksClient{NewWithBaseURI(baseURI, subscriptionID)} 31} 32 33// Get retrieves the details of a VPN site link. 34// Parameters: 35// resourceGroupName - the resource group name of the VpnSite. 36// vpnSiteName - the name of the VpnSite. 37// vpnSiteLinkName - the name of the VpnSiteLink being retrieved. 38func (client VpnSiteLinksClient) Get(ctx context.Context, resourceGroupName string, vpnSiteName string, vpnSiteLinkName string) (result VpnSiteLink, err error) { 39 if tracing.IsEnabled() { 40 ctx = tracing.StartSpan(ctx, fqdn+"/VpnSiteLinksClient.Get") 41 defer func() { 42 sc := -1 43 if result.Response.Response != nil { 44 sc = result.Response.Response.StatusCode 45 } 46 tracing.EndSpan(ctx, sc, err) 47 }() 48 } 49 req, err := client.GetPreparer(ctx, resourceGroupName, vpnSiteName, vpnSiteLinkName) 50 if err != nil { 51 err = autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "Get", nil, "Failure preparing request") 52 return 53 } 54 55 resp, err := client.GetSender(req) 56 if err != nil { 57 result.Response = autorest.Response{Response: resp} 58 err = autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "Get", resp, "Failure sending request") 59 return 60 } 61 62 result, err = client.GetResponder(resp) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "Get", resp, "Failure responding to request") 65 return 66 } 67 68 return 69} 70 71// GetPreparer prepares the Get request. 72func (client VpnSiteLinksClient) GetPreparer(ctx context.Context, resourceGroupName string, vpnSiteName string, vpnSiteLinkName string) (*http.Request, error) { 73 pathParameters := map[string]interface{}{ 74 "resourceGroupName": autorest.Encode("path", resourceGroupName), 75 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 76 "vpnSiteLinkName": autorest.Encode("path", vpnSiteLinkName), 77 "vpnSiteName": autorest.Encode("path", vpnSiteName), 78 } 79 80 const APIVersion = "2020-06-01" 81 queryParameters := map[string]interface{}{ 82 "api-version": APIVersion, 83 } 84 85 preparer := autorest.CreatePreparer( 86 autorest.AsGet(), 87 autorest.WithBaseURL(client.BaseURI), 88 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnSites/{vpnSiteName}/vpnSiteLinks/{vpnSiteLinkName}", pathParameters), 89 autorest.WithQueryParameters(queryParameters)) 90 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 91} 92 93// GetSender sends the Get request. The method will close the 94// http.Response Body if it receives an error. 95func (client VpnSiteLinksClient) GetSender(req *http.Request) (*http.Response, error) { 96 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 97} 98 99// GetResponder handles the response to the Get request. The method always 100// closes the http.Response Body. 101func (client VpnSiteLinksClient) GetResponder(resp *http.Response) (result VpnSiteLink, err error) { 102 err = autorest.Respond( 103 resp, 104 azure.WithErrorUnlessStatusCode(http.StatusOK), 105 autorest.ByUnmarshallingJSON(&result), 106 autorest.ByClosing()) 107 result.Response = autorest.Response{Response: resp} 108 return 109} 110 111// ListByVpnSite lists all the vpnSiteLinks in a resource group for a vpn site. 112// Parameters: 113// resourceGroupName - the resource group name of the VpnSite. 114// vpnSiteName - the name of the VpnSite. 115func (client VpnSiteLinksClient) ListByVpnSite(ctx context.Context, resourceGroupName string, vpnSiteName string) (result ListVpnSiteLinksResultPage, err error) { 116 if tracing.IsEnabled() { 117 ctx = tracing.StartSpan(ctx, fqdn+"/VpnSiteLinksClient.ListByVpnSite") 118 defer func() { 119 sc := -1 120 if result.lvslr.Response.Response != nil { 121 sc = result.lvslr.Response.Response.StatusCode 122 } 123 tracing.EndSpan(ctx, sc, err) 124 }() 125 } 126 result.fn = client.listByVpnSiteNextResults 127 req, err := client.ListByVpnSitePreparer(ctx, resourceGroupName, vpnSiteName) 128 if err != nil { 129 err = autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "ListByVpnSite", nil, "Failure preparing request") 130 return 131 } 132 133 resp, err := client.ListByVpnSiteSender(req) 134 if err != nil { 135 result.lvslr.Response = autorest.Response{Response: resp} 136 err = autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "ListByVpnSite", resp, "Failure sending request") 137 return 138 } 139 140 result.lvslr, err = client.ListByVpnSiteResponder(resp) 141 if err != nil { 142 err = autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "ListByVpnSite", resp, "Failure responding to request") 143 return 144 } 145 if result.lvslr.hasNextLink() && result.lvslr.IsEmpty() { 146 err = result.NextWithContext(ctx) 147 return 148 } 149 150 return 151} 152 153// ListByVpnSitePreparer prepares the ListByVpnSite request. 154func (client VpnSiteLinksClient) ListByVpnSitePreparer(ctx context.Context, resourceGroupName string, vpnSiteName string) (*http.Request, error) { 155 pathParameters := map[string]interface{}{ 156 "resourceGroupName": autorest.Encode("path", resourceGroupName), 157 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 158 "vpnSiteName": autorest.Encode("path", vpnSiteName), 159 } 160 161 const APIVersion = "2020-06-01" 162 queryParameters := map[string]interface{}{ 163 "api-version": APIVersion, 164 } 165 166 preparer := autorest.CreatePreparer( 167 autorest.AsGet(), 168 autorest.WithBaseURL(client.BaseURI), 169 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnSites/{vpnSiteName}/vpnSiteLinks", pathParameters), 170 autorest.WithQueryParameters(queryParameters)) 171 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 172} 173 174// ListByVpnSiteSender sends the ListByVpnSite request. The method will close the 175// http.Response Body if it receives an error. 176func (client VpnSiteLinksClient) ListByVpnSiteSender(req *http.Request) (*http.Response, error) { 177 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 178} 179 180// ListByVpnSiteResponder handles the response to the ListByVpnSite request. The method always 181// closes the http.Response Body. 182func (client VpnSiteLinksClient) ListByVpnSiteResponder(resp *http.Response) (result ListVpnSiteLinksResult, err error) { 183 err = autorest.Respond( 184 resp, 185 azure.WithErrorUnlessStatusCode(http.StatusOK), 186 autorest.ByUnmarshallingJSON(&result), 187 autorest.ByClosing()) 188 result.Response = autorest.Response{Response: resp} 189 return 190} 191 192// listByVpnSiteNextResults retrieves the next set of results, if any. 193func (client VpnSiteLinksClient) listByVpnSiteNextResults(ctx context.Context, lastResults ListVpnSiteLinksResult) (result ListVpnSiteLinksResult, err error) { 194 req, err := lastResults.listVpnSiteLinksResultPreparer(ctx) 195 if err != nil { 196 return result, autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "listByVpnSiteNextResults", nil, "Failure preparing next results request") 197 } 198 if req == nil { 199 return 200 } 201 resp, err := client.ListByVpnSiteSender(req) 202 if err != nil { 203 result.Response = autorest.Response{Response: resp} 204 return result, autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "listByVpnSiteNextResults", resp, "Failure sending next results request") 205 } 206 result, err = client.ListByVpnSiteResponder(resp) 207 if err != nil { 208 err = autorest.NewErrorWithError(err, "network.VpnSiteLinksClient", "listByVpnSiteNextResults", resp, "Failure responding to next results request") 209 } 210 return 211} 212 213// ListByVpnSiteComplete enumerates all values, automatically crossing page boundaries as required. 214func (client VpnSiteLinksClient) ListByVpnSiteComplete(ctx context.Context, resourceGroupName string, vpnSiteName string) (result ListVpnSiteLinksResultIterator, err error) { 215 if tracing.IsEnabled() { 216 ctx = tracing.StartSpan(ctx, fqdn+"/VpnSiteLinksClient.ListByVpnSite") 217 defer func() { 218 sc := -1 219 if result.Response().Response.Response != nil { 220 sc = result.page.Response().Response.Response.StatusCode 221 } 222 tracing.EndSpan(ctx, sc, err) 223 }() 224 } 225 result.page, err = client.ListByVpnSite(ctx, resourceGroupName, vpnSiteName) 226 return 227} 228