github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/managercommits_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 // ManagerCommitsClient contains the methods for the NetworkManagerCommits group. 24 // Don't use this type directly, use NewManagerCommitsClient() instead. 25 type ManagerCommitsClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewManagerCommitsClient creates a new instance of ManagerCommitsClient 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 NewManagerCommitsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ManagerCommitsClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &ManagerCommitsClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // BeginPost - Post a Network Manager Commit. 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 // - networkManagerName - The name of the network manager. 53 // - parameters - Parameters supplied to specify which Managed Network commit is. 54 // - options - ManagerCommitsClientBeginPostOptions contains the optional parameters for the ManagerCommitsClient.BeginPost 55 // method. 56 func (client *ManagerCommitsClient) BeginPost(ctx context.Context, resourceGroupName string, networkManagerName string, parameters ManagerCommit, options *ManagerCommitsClientBeginPostOptions) (*runtime.Poller[ManagerCommitsClientPostResponse], error) { 57 if options == nil || options.ResumeToken == "" { 58 resp, err := client.post(ctx, resourceGroupName, networkManagerName, parameters, options) 59 if err != nil { 60 return nil, err 61 } 62 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ManagerCommitsClientPostResponse]{ 63 FinalStateVia: runtime.FinalStateViaLocation, 64 Tracer: client.internal.Tracer(), 65 }) 66 return poller, err 67 } else { 68 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[ManagerCommitsClientPostResponse]{ 69 Tracer: client.internal.Tracer(), 70 }) 71 } 72 } 73 74 // Post - Post a Network Manager Commit. 75 // If the operation fails it returns an *azcore.ResponseError type. 76 // 77 // Generated from API version 2024-05-01 78 func (client *ManagerCommitsClient) post(ctx context.Context, resourceGroupName string, networkManagerName string, parameters ManagerCommit, options *ManagerCommitsClientBeginPostOptions) (*http.Response, error) { 79 var err error 80 const operationName = "ManagerCommitsClient.BeginPost" 81 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 82 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 83 defer func() { endSpan(err) }() 84 req, err := client.postCreateRequest(ctx, resourceGroupName, networkManagerName, parameters, options) 85 if err != nil { 86 return nil, err 87 } 88 httpResp, err := client.internal.Pipeline().Do(req) 89 if err != nil { 90 return nil, err 91 } 92 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 93 err = runtime.NewResponseError(httpResp) 94 return nil, err 95 } 96 return httpResp, nil 97 } 98 99 // postCreateRequest creates the Post request. 100 func (client *ManagerCommitsClient) postCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, parameters ManagerCommit, options *ManagerCommitsClientBeginPostOptions) (*policy.Request, error) { 101 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/commit" 102 if client.subscriptionID == "" { 103 return nil, errors.New("parameter client.subscriptionID cannot be empty") 104 } 105 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 106 if resourceGroupName == "" { 107 return nil, errors.New("parameter resourceGroupName cannot be empty") 108 } 109 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 110 if networkManagerName == "" { 111 return nil, errors.New("parameter networkManagerName cannot be empty") 112 } 113 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 114 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 115 if err != nil { 116 return nil, err 117 } 118 reqQP := req.Raw().URL.Query() 119 reqQP.Set("api-version", "2024-05-01") 120 req.Raw().URL.RawQuery = reqQP.Encode() 121 req.Raw().Header["Accept"] = []string{"application/json"} 122 if err := runtime.MarshalAsJSON(req, parameters); err != nil { 123 return nil, err 124 } 125 return req, nil 126 }