1// +build go1.13 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// Code generated by Microsoft (R) AutoRest Code Generator. 6// Changes may cause incorrect behavior and will be lost if the code is regenerated. 7 8package armnetwork 9 10import ( 11 "context" 12 "github.com/Azure/azure-sdk-for-go/sdk/armcore" 13 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 14 "net/http" 15 "net/url" 16 "strings" 17 "time" 18) 19 20// VpnServerConfigurationsClient contains the methods for the VpnServerConfigurations group. 21// Don't use this type directly, use NewVpnServerConfigurationsClient() instead. 22type VpnServerConfigurationsClient struct { 23 con *armcore.Connection 24 subscriptionID string 25} 26 27// NewVpnServerConfigurationsClient creates a new instance of VpnServerConfigurationsClient with the specified values. 28func NewVpnServerConfigurationsClient(con *armcore.Connection, subscriptionID string) *VpnServerConfigurationsClient { 29 return &VpnServerConfigurationsClient{con: con, subscriptionID: subscriptionID} 30} 31 32// BeginCreateOrUpdate - Creates a VpnServerConfiguration resource if it doesn't exist else updates the existing VpnServerConfiguration. 33func (client *VpnServerConfigurationsClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, vpnServerConfigurationParameters VpnServerConfiguration, options *VpnServerConfigurationsBeginCreateOrUpdateOptions) (VpnServerConfigurationPollerResponse, error) { 34 resp, err := client.createOrUpdate(ctx, resourceGroupName, vpnServerConfigurationName, vpnServerConfigurationParameters, options) 35 if err != nil { 36 return VpnServerConfigurationPollerResponse{}, err 37 } 38 result := VpnServerConfigurationPollerResponse{ 39 RawResponse: resp.Response, 40 } 41 pt, err := armcore.NewPoller("VpnServerConfigurationsClient.CreateOrUpdate", "azure-async-operation", resp, client.createOrUpdateHandleError) 42 if err != nil { 43 return VpnServerConfigurationPollerResponse{}, err 44 } 45 poller := &vpnServerConfigurationPoller{ 46 pt: pt, 47 pipeline: client.con.Pipeline(), 48 } 49 result.Poller = poller 50 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (VpnServerConfigurationResponse, error) { 51 return poller.pollUntilDone(ctx, frequency) 52 } 53 return result, nil 54} 55 56// ResumeCreateOrUpdate creates a new VpnServerConfigurationPoller from the specified resume token. 57// token - The value must come from a previous call to VpnServerConfigurationPoller.ResumeToken(). 58func (client *VpnServerConfigurationsClient) ResumeCreateOrUpdate(token string) (VpnServerConfigurationPoller, error) { 59 pt, err := armcore.NewPollerFromResumeToken("VpnServerConfigurationsClient.CreateOrUpdate", token, client.createOrUpdateHandleError) 60 if err != nil { 61 return nil, err 62 } 63 return &vpnServerConfigurationPoller{ 64 pipeline: client.con.Pipeline(), 65 pt: pt, 66 }, nil 67} 68 69// CreateOrUpdate - Creates a VpnServerConfiguration resource if it doesn't exist else updates the existing VpnServerConfiguration. 70func (client *VpnServerConfigurationsClient) createOrUpdate(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, vpnServerConfigurationParameters VpnServerConfiguration, options *VpnServerConfigurationsBeginCreateOrUpdateOptions) (*azcore.Response, error) { 71 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, vpnServerConfigurationName, vpnServerConfigurationParameters, options) 72 if err != nil { 73 return nil, err 74 } 75 resp, err := client.con.Pipeline().Do(req) 76 if err != nil { 77 return nil, err 78 } 79 if !resp.HasStatusCode(http.StatusOK, http.StatusCreated) { 80 return nil, client.createOrUpdateHandleError(resp) 81 } 82 return resp, nil 83} 84 85// createOrUpdateCreateRequest creates the CreateOrUpdate request. 86func (client *VpnServerConfigurationsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, vpnServerConfigurationParameters VpnServerConfiguration, options *VpnServerConfigurationsBeginCreateOrUpdateOptions) (*azcore.Request, error) { 87 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnServerConfigurations/{vpnServerConfigurationName}" 88 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 89 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 90 urlPath = strings.ReplaceAll(urlPath, "{vpnServerConfigurationName}", url.PathEscape(vpnServerConfigurationName)) 91 req, err := azcore.NewRequest(ctx, http.MethodPut, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 92 if err != nil { 93 return nil, err 94 } 95 req.Telemetry(telemetryInfo) 96 query := req.URL.Query() 97 query.Set("api-version", "2020-07-01") 98 req.URL.RawQuery = query.Encode() 99 req.Header.Set("Accept", "application/json") 100 return req, req.MarshalAsJSON(vpnServerConfigurationParameters) 101} 102 103// createOrUpdateHandleResponse handles the CreateOrUpdate response. 104func (client *VpnServerConfigurationsClient) createOrUpdateHandleResponse(resp *azcore.Response) (VpnServerConfigurationResponse, error) { 105 var val *VpnServerConfiguration 106 if err := resp.UnmarshalAsJSON(&val); err != nil { 107 return VpnServerConfigurationResponse{}, err 108 } 109 return VpnServerConfigurationResponse{RawResponse: resp.Response, VpnServerConfiguration: val}, nil 110} 111 112// createOrUpdateHandleError handles the CreateOrUpdate error response. 113func (client *VpnServerConfigurationsClient) createOrUpdateHandleError(resp *azcore.Response) error { 114 var err CloudError 115 if err := resp.UnmarshalAsJSON(&err); err != nil { 116 return err 117 } 118 return azcore.NewResponseError(&err, resp.Response) 119} 120 121// BeginDelete - Deletes a VpnServerConfiguration. 122func (client *VpnServerConfigurationsClient) BeginDelete(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, options *VpnServerConfigurationsBeginDeleteOptions) (HTTPPollerResponse, error) { 123 resp, err := client.delete(ctx, resourceGroupName, vpnServerConfigurationName, options) 124 if err != nil { 125 return HTTPPollerResponse{}, err 126 } 127 result := HTTPPollerResponse{ 128 RawResponse: resp.Response, 129 } 130 pt, err := armcore.NewPoller("VpnServerConfigurationsClient.Delete", "location", resp, client.deleteHandleError) 131 if err != nil { 132 return HTTPPollerResponse{}, err 133 } 134 poller := &httpPoller{ 135 pt: pt, 136 pipeline: client.con.Pipeline(), 137 } 138 result.Poller = poller 139 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (*http.Response, error) { 140 return poller.pollUntilDone(ctx, frequency) 141 } 142 return result, nil 143} 144 145// ResumeDelete creates a new HTTPPoller from the specified resume token. 146// token - The value must come from a previous call to HTTPPoller.ResumeToken(). 147func (client *VpnServerConfigurationsClient) ResumeDelete(token string) (HTTPPoller, error) { 148 pt, err := armcore.NewPollerFromResumeToken("VpnServerConfigurationsClient.Delete", token, client.deleteHandleError) 149 if err != nil { 150 return nil, err 151 } 152 return &httpPoller{ 153 pipeline: client.con.Pipeline(), 154 pt: pt, 155 }, nil 156} 157 158// Delete - Deletes a VpnServerConfiguration. 159func (client *VpnServerConfigurationsClient) delete(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, options *VpnServerConfigurationsBeginDeleteOptions) (*azcore.Response, error) { 160 req, err := client.deleteCreateRequest(ctx, resourceGroupName, vpnServerConfigurationName, options) 161 if err != nil { 162 return nil, err 163 } 164 resp, err := client.con.Pipeline().Do(req) 165 if err != nil { 166 return nil, err 167 } 168 if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 169 return nil, client.deleteHandleError(resp) 170 } 171 return resp, nil 172} 173 174// deleteCreateRequest creates the Delete request. 175func (client *VpnServerConfigurationsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, options *VpnServerConfigurationsBeginDeleteOptions) (*azcore.Request, error) { 176 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnServerConfigurations/{vpnServerConfigurationName}" 177 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 178 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 179 urlPath = strings.ReplaceAll(urlPath, "{vpnServerConfigurationName}", url.PathEscape(vpnServerConfigurationName)) 180 req, err := azcore.NewRequest(ctx, http.MethodDelete, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 181 if err != nil { 182 return nil, err 183 } 184 req.Telemetry(telemetryInfo) 185 query := req.URL.Query() 186 query.Set("api-version", "2020-07-01") 187 req.URL.RawQuery = query.Encode() 188 req.Header.Set("Accept", "application/json") 189 return req, nil 190} 191 192// deleteHandleError handles the Delete error response. 193func (client *VpnServerConfigurationsClient) deleteHandleError(resp *azcore.Response) error { 194 var err CloudError 195 if err := resp.UnmarshalAsJSON(&err); err != nil { 196 return err 197 } 198 return azcore.NewResponseError(&err, resp.Response) 199} 200 201// Get - Retrieves the details of a VpnServerConfiguration. 202func (client *VpnServerConfigurationsClient) Get(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, options *VpnServerConfigurationsGetOptions) (VpnServerConfigurationResponse, error) { 203 req, err := client.getCreateRequest(ctx, resourceGroupName, vpnServerConfigurationName, options) 204 if err != nil { 205 return VpnServerConfigurationResponse{}, err 206 } 207 resp, err := client.con.Pipeline().Do(req) 208 if err != nil { 209 return VpnServerConfigurationResponse{}, err 210 } 211 if !resp.HasStatusCode(http.StatusOK) { 212 return VpnServerConfigurationResponse{}, client.getHandleError(resp) 213 } 214 return client.getHandleResponse(resp) 215} 216 217// getCreateRequest creates the Get request. 218func (client *VpnServerConfigurationsClient) getCreateRequest(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, options *VpnServerConfigurationsGetOptions) (*azcore.Request, error) { 219 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnServerConfigurations/{vpnServerConfigurationName}" 220 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 221 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 222 urlPath = strings.ReplaceAll(urlPath, "{vpnServerConfigurationName}", url.PathEscape(vpnServerConfigurationName)) 223 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 224 if err != nil { 225 return nil, err 226 } 227 req.Telemetry(telemetryInfo) 228 query := req.URL.Query() 229 query.Set("api-version", "2020-07-01") 230 req.URL.RawQuery = query.Encode() 231 req.Header.Set("Accept", "application/json") 232 return req, nil 233} 234 235// getHandleResponse handles the Get response. 236func (client *VpnServerConfigurationsClient) getHandleResponse(resp *azcore.Response) (VpnServerConfigurationResponse, error) { 237 var val *VpnServerConfiguration 238 if err := resp.UnmarshalAsJSON(&val); err != nil { 239 return VpnServerConfigurationResponse{}, err 240 } 241 return VpnServerConfigurationResponse{RawResponse: resp.Response, VpnServerConfiguration: val}, nil 242} 243 244// getHandleError handles the Get error response. 245func (client *VpnServerConfigurationsClient) getHandleError(resp *azcore.Response) error { 246 var err CloudError 247 if err := resp.UnmarshalAsJSON(&err); err != nil { 248 return err 249 } 250 return azcore.NewResponseError(&err, resp.Response) 251} 252 253// List - Lists all the VpnServerConfigurations in a subscription. 254func (client *VpnServerConfigurationsClient) List(options *VpnServerConfigurationsListOptions) ListVpnServerConfigurationsResultPager { 255 return &listVpnServerConfigurationsResultPager{ 256 pipeline: client.con.Pipeline(), 257 requester: func(ctx context.Context) (*azcore.Request, error) { 258 return client.listCreateRequest(ctx, options) 259 }, 260 responder: client.listHandleResponse, 261 errorer: client.listHandleError, 262 advancer: func(ctx context.Context, resp ListVpnServerConfigurationsResultResponse) (*azcore.Request, error) { 263 return azcore.NewRequest(ctx, http.MethodGet, *resp.ListVpnServerConfigurationsResult.NextLink) 264 }, 265 statusCodes: []int{http.StatusOK}, 266 } 267} 268 269// listCreateRequest creates the List request. 270func (client *VpnServerConfigurationsClient) listCreateRequest(ctx context.Context, options *VpnServerConfigurationsListOptions) (*azcore.Request, error) { 271 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/vpnServerConfigurations" 272 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 273 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 274 if err != nil { 275 return nil, err 276 } 277 req.Telemetry(telemetryInfo) 278 query := req.URL.Query() 279 query.Set("api-version", "2020-07-01") 280 req.URL.RawQuery = query.Encode() 281 req.Header.Set("Accept", "application/json") 282 return req, nil 283} 284 285// listHandleResponse handles the List response. 286func (client *VpnServerConfigurationsClient) listHandleResponse(resp *azcore.Response) (ListVpnServerConfigurationsResultResponse, error) { 287 var val *ListVpnServerConfigurationsResult 288 if err := resp.UnmarshalAsJSON(&val); err != nil { 289 return ListVpnServerConfigurationsResultResponse{}, err 290 } 291 return ListVpnServerConfigurationsResultResponse{RawResponse: resp.Response, ListVpnServerConfigurationsResult: val}, nil 292} 293 294// listHandleError handles the List error response. 295func (client *VpnServerConfigurationsClient) listHandleError(resp *azcore.Response) error { 296 var err CloudError 297 if err := resp.UnmarshalAsJSON(&err); err != nil { 298 return err 299 } 300 return azcore.NewResponseError(&err, resp.Response) 301} 302 303// ListByResourceGroup - Lists all the vpnServerConfigurations in a resource group. 304func (client *VpnServerConfigurationsClient) ListByResourceGroup(resourceGroupName string, options *VpnServerConfigurationsListByResourceGroupOptions) ListVpnServerConfigurationsResultPager { 305 return &listVpnServerConfigurationsResultPager{ 306 pipeline: client.con.Pipeline(), 307 requester: func(ctx context.Context) (*azcore.Request, error) { 308 return client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) 309 }, 310 responder: client.listByResourceGroupHandleResponse, 311 errorer: client.listByResourceGroupHandleError, 312 advancer: func(ctx context.Context, resp ListVpnServerConfigurationsResultResponse) (*azcore.Request, error) { 313 return azcore.NewRequest(ctx, http.MethodGet, *resp.ListVpnServerConfigurationsResult.NextLink) 314 }, 315 statusCodes: []int{http.StatusOK}, 316 } 317} 318 319// listByResourceGroupCreateRequest creates the ListByResourceGroup request. 320func (client *VpnServerConfigurationsClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, options *VpnServerConfigurationsListByResourceGroupOptions) (*azcore.Request, error) { 321 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnServerConfigurations" 322 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 323 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 324 req, err := azcore.NewRequest(ctx, http.MethodGet, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 325 if err != nil { 326 return nil, err 327 } 328 req.Telemetry(telemetryInfo) 329 query := req.URL.Query() 330 query.Set("api-version", "2020-07-01") 331 req.URL.RawQuery = query.Encode() 332 req.Header.Set("Accept", "application/json") 333 return req, nil 334} 335 336// listByResourceGroupHandleResponse handles the ListByResourceGroup response. 337func (client *VpnServerConfigurationsClient) listByResourceGroupHandleResponse(resp *azcore.Response) (ListVpnServerConfigurationsResultResponse, error) { 338 var val *ListVpnServerConfigurationsResult 339 if err := resp.UnmarshalAsJSON(&val); err != nil { 340 return ListVpnServerConfigurationsResultResponse{}, err 341 } 342 return ListVpnServerConfigurationsResultResponse{RawResponse: resp.Response, ListVpnServerConfigurationsResult: val}, nil 343} 344 345// listByResourceGroupHandleError handles the ListByResourceGroup error response. 346func (client *VpnServerConfigurationsClient) listByResourceGroupHandleError(resp *azcore.Response) error { 347 var err CloudError 348 if err := resp.UnmarshalAsJSON(&err); err != nil { 349 return err 350 } 351 return azcore.NewResponseError(&err, resp.Response) 352} 353 354// UpdateTags - Updates VpnServerConfiguration tags. 355func (client *VpnServerConfigurationsClient) UpdateTags(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, vpnServerConfigurationParameters TagsObject, options *VpnServerConfigurationsUpdateTagsOptions) (VpnServerConfigurationResponse, error) { 356 req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, vpnServerConfigurationName, vpnServerConfigurationParameters, options) 357 if err != nil { 358 return VpnServerConfigurationResponse{}, err 359 } 360 resp, err := client.con.Pipeline().Do(req) 361 if err != nil { 362 return VpnServerConfigurationResponse{}, err 363 } 364 if !resp.HasStatusCode(http.StatusOK) { 365 return VpnServerConfigurationResponse{}, client.updateTagsHandleError(resp) 366 } 367 return client.updateTagsHandleResponse(resp) 368} 369 370// updateTagsCreateRequest creates the UpdateTags request. 371func (client *VpnServerConfigurationsClient) updateTagsCreateRequest(ctx context.Context, resourceGroupName string, vpnServerConfigurationName string, vpnServerConfigurationParameters TagsObject, options *VpnServerConfigurationsUpdateTagsOptions) (*azcore.Request, error) { 372 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnServerConfigurations/{vpnServerConfigurationName}" 373 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 374 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 375 urlPath = strings.ReplaceAll(urlPath, "{vpnServerConfigurationName}", url.PathEscape(vpnServerConfigurationName)) 376 req, err := azcore.NewRequest(ctx, http.MethodPatch, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 377 if err != nil { 378 return nil, err 379 } 380 req.Telemetry(telemetryInfo) 381 query := req.URL.Query() 382 query.Set("api-version", "2020-07-01") 383 req.URL.RawQuery = query.Encode() 384 req.Header.Set("Accept", "application/json") 385 return req, req.MarshalAsJSON(vpnServerConfigurationParameters) 386} 387 388// updateTagsHandleResponse handles the UpdateTags response. 389func (client *VpnServerConfigurationsClient) updateTagsHandleResponse(resp *azcore.Response) (VpnServerConfigurationResponse, error) { 390 var val *VpnServerConfiguration 391 if err := resp.UnmarshalAsJSON(&val); err != nil { 392 return VpnServerConfigurationResponse{}, err 393 } 394 return VpnServerConfigurationResponse{RawResponse: resp.Response, VpnServerConfiguration: val}, nil 395} 396 397// updateTagsHandleError handles the UpdateTags error response. 398func (client *VpnServerConfigurationsClient) updateTagsHandleError(resp *azcore.Response) error { 399 var err CloudError 400 if err := resp.UnmarshalAsJSON(&err); err != nil { 401 return err 402 } 403 return azcore.NewResponseError(&err, resp.Response) 404} 405