github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/profiles_client.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // Licensed under the MIT License. See License.txt in the project root for license information. 6 // Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. 7 // Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9 package armnetwork 10 11 import ( 12 "context" 13 "errors" 14 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" 16 "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" 17 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" 18 "net/http" 19 "net/url" 20 "strings" 21 ) 22 23 // ProfilesClient contains the methods for the NetworkProfiles group. 24 // Don't use this type directly, use NewProfilesClient() instead. 25 type ProfilesClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewProfilesClient creates a new instance of ProfilesClient with the specified values. 31 // - subscriptionID - The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription 32 // ID forms part of the URI for every service call. 33 // - credential - used to authorize requests. Usually a credential from azidentity. 34 // - options - pass nil to accept the default values. 35 func NewProfilesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ProfilesClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &ProfilesClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // CreateOrUpdate - Creates or updates a network profile. 48 // If the operation fails it returns an *azcore.ResponseError type. 49 // 50 // Generated from API version 2024-05-01 51 // - resourceGroupName - The name of the resource group. 52 // - networkProfileName - The name of the network profile. 53 // - parameters - Parameters supplied to the create or update network profile operation. 54 // - options - ProfilesClientCreateOrUpdateOptions contains the optional parameters for the ProfilesClient.CreateOrUpdate method. 55 func (client *ProfilesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkProfileName string, parameters Profile, options *ProfilesClientCreateOrUpdateOptions) (ProfilesClientCreateOrUpdateResponse, error) { 56 var err error 57 const operationName = "ProfilesClient.CreateOrUpdate" 58 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 59 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 60 defer func() { endSpan(err) }() 61 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, networkProfileName, parameters, options) 62 if err != nil { 63 return ProfilesClientCreateOrUpdateResponse{}, err 64 } 65 httpResp, err := client.internal.Pipeline().Do(req) 66 if err != nil { 67 return ProfilesClientCreateOrUpdateResponse{}, err 68 } 69 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { 70 err = runtime.NewResponseError(httpResp) 71 return ProfilesClientCreateOrUpdateResponse{}, err 72 } 73 resp, err := client.createOrUpdateHandleResponse(httpResp) 74 return resp, err 75 } 76 77 // createOrUpdateCreateRequest creates the CreateOrUpdate request. 78 func (client *ProfilesClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, networkProfileName string, parameters Profile, options *ProfilesClientCreateOrUpdateOptions) (*policy.Request, error) { 79 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles/{networkProfileName}" 80 if resourceGroupName == "" { 81 return nil, errors.New("parameter resourceGroupName cannot be empty") 82 } 83 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 84 if networkProfileName == "" { 85 return nil, errors.New("parameter networkProfileName cannot be empty") 86 } 87 urlPath = strings.ReplaceAll(urlPath, "{networkProfileName}", url.PathEscape(networkProfileName)) 88 if client.subscriptionID == "" { 89 return nil, errors.New("parameter client.subscriptionID cannot be empty") 90 } 91 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 92 req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 93 if err != nil { 94 return nil, err 95 } 96 reqQP := req.Raw().URL.Query() 97 reqQP.Set("api-version", "2024-05-01") 98 req.Raw().URL.RawQuery = reqQP.Encode() 99 req.Raw().Header["Accept"] = []string{"application/json"} 100 if err := runtime.MarshalAsJSON(req, parameters); err != nil { 101 return nil, err 102 } 103 return req, nil 104 } 105 106 // createOrUpdateHandleResponse handles the CreateOrUpdate response. 107 func (client *ProfilesClient) createOrUpdateHandleResponse(resp *http.Response) (ProfilesClientCreateOrUpdateResponse, error) { 108 result := ProfilesClientCreateOrUpdateResponse{} 109 if err := runtime.UnmarshalAsJSON(resp, &result.Profile); err != nil { 110 return ProfilesClientCreateOrUpdateResponse{}, err 111 } 112 return result, nil 113 } 114 115 // BeginDelete - Deletes the specified network profile. 116 // If the operation fails it returns an *azcore.ResponseError type. 117 // 118 // Generated from API version 2024-05-01 119 // - resourceGroupName - The name of the resource group. 120 // - networkProfileName - The name of the NetworkProfile. 121 // - options - ProfilesClientBeginDeleteOptions contains the optional parameters for the ProfilesClient.BeginDelete method. 122 func (client *ProfilesClient) BeginDelete(ctx context.Context, resourceGroupName string, networkProfileName string, options *ProfilesClientBeginDeleteOptions) (*runtime.Poller[ProfilesClientDeleteResponse], error) { 123 if options == nil || options.ResumeToken == "" { 124 resp, err := client.deleteOperation(ctx, resourceGroupName, networkProfileName, options) 125 if err != nil { 126 return nil, err 127 } 128 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ProfilesClientDeleteResponse]{ 129 FinalStateVia: runtime.FinalStateViaLocation, 130 Tracer: client.internal.Tracer(), 131 }) 132 return poller, err 133 } else { 134 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ProfilesClientDeleteResponse]{ 135 Tracer: client.internal.Tracer(), 136 }) 137 } 138 } 139 140 // Delete - Deletes the specified network profile. 141 // If the operation fails it returns an *azcore.ResponseError type. 142 // 143 // Generated from API version 2024-05-01 144 func (client *ProfilesClient) deleteOperation(ctx context.Context, resourceGroupName string, networkProfileName string, options *ProfilesClientBeginDeleteOptions) (*http.Response, error) { 145 var err error 146 const operationName = "ProfilesClient.BeginDelete" 147 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 148 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 149 defer func() { endSpan(err) }() 150 req, err := client.deleteCreateRequest(ctx, resourceGroupName, networkProfileName, options) 151 if err != nil { 152 return nil, err 153 } 154 httpResp, err := client.internal.Pipeline().Do(req) 155 if err != nil { 156 return nil, err 157 } 158 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 159 err = runtime.NewResponseError(httpResp) 160 return nil, err 161 } 162 return httpResp, nil 163 } 164 165 // deleteCreateRequest creates the Delete request. 166 func (client *ProfilesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, networkProfileName string, options *ProfilesClientBeginDeleteOptions) (*policy.Request, error) { 167 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles/{networkProfileName}" 168 if resourceGroupName == "" { 169 return nil, errors.New("parameter resourceGroupName cannot be empty") 170 } 171 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 172 if networkProfileName == "" { 173 return nil, errors.New("parameter networkProfileName cannot be empty") 174 } 175 urlPath = strings.ReplaceAll(urlPath, "{networkProfileName}", url.PathEscape(networkProfileName)) 176 if client.subscriptionID == "" { 177 return nil, errors.New("parameter client.subscriptionID cannot be empty") 178 } 179 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 180 req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 181 if err != nil { 182 return nil, err 183 } 184 reqQP := req.Raw().URL.Query() 185 reqQP.Set("api-version", "2024-05-01") 186 req.Raw().URL.RawQuery = reqQP.Encode() 187 req.Raw().Header["Accept"] = []string{"application/json"} 188 return req, nil 189 } 190 191 // Get - Gets the specified network profile in a specified resource group. 192 // If the operation fails it returns an *azcore.ResponseError type. 193 // 194 // Generated from API version 2024-05-01 195 // - resourceGroupName - The name of the resource group. 196 // - networkProfileName - The name of the public IP prefix. 197 // - options - ProfilesClientGetOptions contains the optional parameters for the ProfilesClient.Get method. 198 func (client *ProfilesClient) Get(ctx context.Context, resourceGroupName string, networkProfileName string, options *ProfilesClientGetOptions) (ProfilesClientGetResponse, error) { 199 var err error 200 const operationName = "ProfilesClient.Get" 201 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 202 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 203 defer func() { endSpan(err) }() 204 req, err := client.getCreateRequest(ctx, resourceGroupName, networkProfileName, options) 205 if err != nil { 206 return ProfilesClientGetResponse{}, err 207 } 208 httpResp, err := client.internal.Pipeline().Do(req) 209 if err != nil { 210 return ProfilesClientGetResponse{}, err 211 } 212 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 213 err = runtime.NewResponseError(httpResp) 214 return ProfilesClientGetResponse{}, err 215 } 216 resp, err := client.getHandleResponse(httpResp) 217 return resp, err 218 } 219 220 // getCreateRequest creates the Get request. 221 func (client *ProfilesClient) getCreateRequest(ctx context.Context, resourceGroupName string, networkProfileName string, options *ProfilesClientGetOptions) (*policy.Request, error) { 222 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles/{networkProfileName}" 223 if resourceGroupName == "" { 224 return nil, errors.New("parameter resourceGroupName cannot be empty") 225 } 226 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 227 if networkProfileName == "" { 228 return nil, errors.New("parameter networkProfileName cannot be empty") 229 } 230 urlPath = strings.ReplaceAll(urlPath, "{networkProfileName}", url.PathEscape(networkProfileName)) 231 if client.subscriptionID == "" { 232 return nil, errors.New("parameter client.subscriptionID cannot be empty") 233 } 234 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 235 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 236 if err != nil { 237 return nil, err 238 } 239 reqQP := req.Raw().URL.Query() 240 if options != nil && options.Expand != nil { 241 reqQP.Set("$expand", *options.Expand) 242 } 243 reqQP.Set("api-version", "2024-05-01") 244 req.Raw().URL.RawQuery = reqQP.Encode() 245 req.Raw().Header["Accept"] = []string{"application/json"} 246 return req, nil 247 } 248 249 // getHandleResponse handles the Get response. 250 func (client *ProfilesClient) getHandleResponse(resp *http.Response) (ProfilesClientGetResponse, error) { 251 result := ProfilesClientGetResponse{} 252 if err := runtime.UnmarshalAsJSON(resp, &result.Profile); err != nil { 253 return ProfilesClientGetResponse{}, err 254 } 255 return result, nil 256 } 257 258 // NewListPager - Gets all network profiles in a resource group. 259 // 260 // Generated from API version 2024-05-01 261 // - resourceGroupName - The name of the resource group. 262 // - options - ProfilesClientListOptions contains the optional parameters for the ProfilesClient.NewListPager method. 263 func (client *ProfilesClient) NewListPager(resourceGroupName string, options *ProfilesClientListOptions) *runtime.Pager[ProfilesClientListResponse] { 264 return runtime.NewPager(runtime.PagingHandler[ProfilesClientListResponse]{ 265 More: func(page ProfilesClientListResponse) bool { 266 return page.NextLink != nil && len(*page.NextLink) > 0 267 }, 268 Fetcher: func(ctx context.Context, page *ProfilesClientListResponse) (ProfilesClientListResponse, error) { 269 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ProfilesClient.NewListPager") 270 nextLink := "" 271 if page != nil { 272 nextLink = *page.NextLink 273 } 274 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 275 return client.listCreateRequest(ctx, resourceGroupName, options) 276 }, nil) 277 if err != nil { 278 return ProfilesClientListResponse{}, err 279 } 280 return client.listHandleResponse(resp) 281 }, 282 Tracer: client.internal.Tracer(), 283 }) 284 } 285 286 // listCreateRequest creates the List request. 287 func (client *ProfilesClient) listCreateRequest(ctx context.Context, resourceGroupName string, options *ProfilesClientListOptions) (*policy.Request, error) { 288 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles" 289 if resourceGroupName == "" { 290 return nil, errors.New("parameter resourceGroupName cannot be empty") 291 } 292 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 293 if client.subscriptionID == "" { 294 return nil, errors.New("parameter client.subscriptionID cannot be empty") 295 } 296 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 297 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 298 if err != nil { 299 return nil, err 300 } 301 reqQP := req.Raw().URL.Query() 302 reqQP.Set("api-version", "2024-05-01") 303 req.Raw().URL.RawQuery = reqQP.Encode() 304 req.Raw().Header["Accept"] = []string{"application/json"} 305 return req, nil 306 } 307 308 // listHandleResponse handles the List response. 309 func (client *ProfilesClient) listHandleResponse(resp *http.Response) (ProfilesClientListResponse, error) { 310 result := ProfilesClientListResponse{} 311 if err := runtime.UnmarshalAsJSON(resp, &result.ProfileListResult); err != nil { 312 return ProfilesClientListResponse{}, err 313 } 314 return result, nil 315 } 316 317 // NewListAllPager - Gets all the network profiles in a subscription. 318 // 319 // Generated from API version 2024-05-01 320 // - options - ProfilesClientListAllOptions contains the optional parameters for the ProfilesClient.NewListAllPager method. 321 func (client *ProfilesClient) NewListAllPager(options *ProfilesClientListAllOptions) *runtime.Pager[ProfilesClientListAllResponse] { 322 return runtime.NewPager(runtime.PagingHandler[ProfilesClientListAllResponse]{ 323 More: func(page ProfilesClientListAllResponse) bool { 324 return page.NextLink != nil && len(*page.NextLink) > 0 325 }, 326 Fetcher: func(ctx context.Context, page *ProfilesClientListAllResponse) (ProfilesClientListAllResponse, error) { 327 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ProfilesClient.NewListAllPager") 328 nextLink := "" 329 if page != nil { 330 nextLink = *page.NextLink 331 } 332 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 333 return client.listAllCreateRequest(ctx, options) 334 }, nil) 335 if err != nil { 336 return ProfilesClientListAllResponse{}, err 337 } 338 return client.listAllHandleResponse(resp) 339 }, 340 Tracer: client.internal.Tracer(), 341 }) 342 } 343 344 // listAllCreateRequest creates the ListAll request. 345 func (client *ProfilesClient) listAllCreateRequest(ctx context.Context, options *ProfilesClientListAllOptions) (*policy.Request, error) { 346 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/networkProfiles" 347 if client.subscriptionID == "" { 348 return nil, errors.New("parameter client.subscriptionID cannot be empty") 349 } 350 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 351 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 352 if err != nil { 353 return nil, err 354 } 355 reqQP := req.Raw().URL.Query() 356 reqQP.Set("api-version", "2024-05-01") 357 req.Raw().URL.RawQuery = reqQP.Encode() 358 req.Raw().Header["Accept"] = []string{"application/json"} 359 return req, nil 360 } 361 362 // listAllHandleResponse handles the ListAll response. 363 func (client *ProfilesClient) listAllHandleResponse(resp *http.Response) (ProfilesClientListAllResponse, error) { 364 result := ProfilesClientListAllResponse{} 365 if err := runtime.UnmarshalAsJSON(resp, &result.ProfileListResult); err != nil { 366 return ProfilesClientListAllResponse{}, err 367 } 368 return result, nil 369 } 370 371 // UpdateTags - Updates network profile tags. 372 // If the operation fails it returns an *azcore.ResponseError type. 373 // 374 // Generated from API version 2024-05-01 375 // - resourceGroupName - The name of the resource group. 376 // - networkProfileName - The name of the network profile. 377 // - parameters - Parameters supplied to update network profile tags. 378 // - options - ProfilesClientUpdateTagsOptions contains the optional parameters for the ProfilesClient.UpdateTags method. 379 func (client *ProfilesClient) UpdateTags(ctx context.Context, resourceGroupName string, networkProfileName string, parameters TagsObject, options *ProfilesClientUpdateTagsOptions) (ProfilesClientUpdateTagsResponse, error) { 380 var err error 381 const operationName = "ProfilesClient.UpdateTags" 382 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 383 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 384 defer func() { endSpan(err) }() 385 req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, networkProfileName, parameters, options) 386 if err != nil { 387 return ProfilesClientUpdateTagsResponse{}, err 388 } 389 httpResp, err := client.internal.Pipeline().Do(req) 390 if err != nil { 391 return ProfilesClientUpdateTagsResponse{}, err 392 } 393 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 394 err = runtime.NewResponseError(httpResp) 395 return ProfilesClientUpdateTagsResponse{}, err 396 } 397 resp, err := client.updateTagsHandleResponse(httpResp) 398 return resp, err 399 } 400 401 // updateTagsCreateRequest creates the UpdateTags request. 402 func (client *ProfilesClient) updateTagsCreateRequest(ctx context.Context, resourceGroupName string, networkProfileName string, parameters TagsObject, options *ProfilesClientUpdateTagsOptions) (*policy.Request, error) { 403 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkProfiles/{networkProfileName}" 404 if resourceGroupName == "" { 405 return nil, errors.New("parameter resourceGroupName cannot be empty") 406 } 407 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 408 if networkProfileName == "" { 409 return nil, errors.New("parameter networkProfileName cannot be empty") 410 } 411 urlPath = strings.ReplaceAll(urlPath, "{networkProfileName}", url.PathEscape(networkProfileName)) 412 if client.subscriptionID == "" { 413 return nil, errors.New("parameter client.subscriptionID cannot be empty") 414 } 415 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 416 req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 417 if err != nil { 418 return nil, err 419 } 420 reqQP := req.Raw().URL.Query() 421 reqQP.Set("api-version", "2024-05-01") 422 req.Raw().URL.RawQuery = reqQP.Encode() 423 req.Raw().Header["Accept"] = []string{"application/json"} 424 if err := runtime.MarshalAsJSON(req, parameters); err != nil { 425 return nil, err 426 } 427 return req, nil 428 } 429 430 // updateTagsHandleResponse handles the UpdateTags response. 431 func (client *ProfilesClient) updateTagsHandleResponse(resp *http.Response) (ProfilesClientUpdateTagsResponse, error) { 432 result := ProfilesClientUpdateTagsResponse{} 433 if err := runtime.UnmarshalAsJSON(resp, &result.Profile); err != nil { 434 return ProfilesClientUpdateTagsResponse{}, err 435 } 436 return result, nil 437 }