github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/firewallpolicydrafts_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 // FirewallPolicyDraftsClient contains the methods for the FirewallPolicyDrafts group. 24 // Don't use this type directly, use NewFirewallPolicyDraftsClient() instead. 25 type FirewallPolicyDraftsClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewFirewallPolicyDraftsClient creates a new instance of FirewallPolicyDraftsClient 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 NewFirewallPolicyDraftsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*FirewallPolicyDraftsClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &FirewallPolicyDraftsClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // CreateOrUpdate - Create or update a draft Firewall Policy. 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 // - firewallPolicyName - The name of the Firewall Policy. 53 // - parameters - Parameters supplied to the create or update Firewall Policy Draft operation. 54 // - options - FirewallPolicyDraftsClientCreateOrUpdateOptions contains the optional parameters for the FirewallPolicyDraftsClient.CreateOrUpdate 55 // method. 56 func (client *FirewallPolicyDraftsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters FirewallPolicyDraft, options *FirewallPolicyDraftsClientCreateOrUpdateOptions) (FirewallPolicyDraftsClientCreateOrUpdateResponse, error) { 57 var err error 58 const operationName = "FirewallPolicyDraftsClient.CreateOrUpdate" 59 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 60 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 61 defer func() { endSpan(err) }() 62 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, firewallPolicyName, parameters, options) 63 if err != nil { 64 return FirewallPolicyDraftsClientCreateOrUpdateResponse{}, err 65 } 66 httpResp, err := client.internal.Pipeline().Do(req) 67 if err != nil { 68 return FirewallPolicyDraftsClientCreateOrUpdateResponse{}, err 69 } 70 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { 71 err = runtime.NewResponseError(httpResp) 72 return FirewallPolicyDraftsClientCreateOrUpdateResponse{}, err 73 } 74 resp, err := client.createOrUpdateHandleResponse(httpResp) 75 return resp, err 76 } 77 78 // createOrUpdateCreateRequest creates the CreateOrUpdate request. 79 func (client *FirewallPolicyDraftsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters FirewallPolicyDraft, options *FirewallPolicyDraftsClientCreateOrUpdateOptions) (*policy.Request, error) { 80 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/firewallPolicies/{firewallPolicyName}/firewallPolicyDrafts/default" 81 if resourceGroupName == "" { 82 return nil, errors.New("parameter resourceGroupName cannot be empty") 83 } 84 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 85 if firewallPolicyName == "" { 86 return nil, errors.New("parameter firewallPolicyName cannot be empty") 87 } 88 urlPath = strings.ReplaceAll(urlPath, "{firewallPolicyName}", url.PathEscape(firewallPolicyName)) 89 if client.subscriptionID == "" { 90 return nil, errors.New("parameter client.subscriptionID cannot be empty") 91 } 92 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 93 req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 94 if err != nil { 95 return nil, err 96 } 97 reqQP := req.Raw().URL.Query() 98 reqQP.Set("api-version", "2024-05-01") 99 req.Raw().URL.RawQuery = reqQP.Encode() 100 req.Raw().Header["Accept"] = []string{"application/json"} 101 if err := runtime.MarshalAsJSON(req, parameters); err != nil { 102 return nil, err 103 } 104 return req, nil 105 } 106 107 // createOrUpdateHandleResponse handles the CreateOrUpdate response. 108 func (client *FirewallPolicyDraftsClient) createOrUpdateHandleResponse(resp *http.Response) (FirewallPolicyDraftsClientCreateOrUpdateResponse, error) { 109 result := FirewallPolicyDraftsClientCreateOrUpdateResponse{} 110 if err := runtime.UnmarshalAsJSON(resp, &result.FirewallPolicyDraft); err != nil { 111 return FirewallPolicyDraftsClientCreateOrUpdateResponse{}, err 112 } 113 return result, nil 114 } 115 116 // Delete - Delete a draft policy. 117 // If the operation fails it returns an *azcore.ResponseError type. 118 // 119 // Generated from API version 2024-05-01 120 // - resourceGroupName - The name of the resource group. 121 // - firewallPolicyName - The name of the Firewall Policy. 122 // - options - FirewallPolicyDraftsClientDeleteOptions contains the optional parameters for the FirewallPolicyDraftsClient.Delete 123 // method. 124 func (client *FirewallPolicyDraftsClient) Delete(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *FirewallPolicyDraftsClientDeleteOptions) (FirewallPolicyDraftsClientDeleteResponse, error) { 125 var err error 126 const operationName = "FirewallPolicyDraftsClient.Delete" 127 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 128 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 129 defer func() { endSpan(err) }() 130 req, err := client.deleteCreateRequest(ctx, resourceGroupName, firewallPolicyName, options) 131 if err != nil { 132 return FirewallPolicyDraftsClientDeleteResponse{}, err 133 } 134 httpResp, err := client.internal.Pipeline().Do(req) 135 if err != nil { 136 return FirewallPolicyDraftsClientDeleteResponse{}, err 137 } 138 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) { 139 err = runtime.NewResponseError(httpResp) 140 return FirewallPolicyDraftsClientDeleteResponse{}, err 141 } 142 return FirewallPolicyDraftsClientDeleteResponse{}, nil 143 } 144 145 // deleteCreateRequest creates the Delete request. 146 func (client *FirewallPolicyDraftsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *FirewallPolicyDraftsClientDeleteOptions) (*policy.Request, error) { 147 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/firewallPolicies/{firewallPolicyName}/firewallPolicyDrafts/default" 148 if resourceGroupName == "" { 149 return nil, errors.New("parameter resourceGroupName cannot be empty") 150 } 151 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 152 if firewallPolicyName == "" { 153 return nil, errors.New("parameter firewallPolicyName cannot be empty") 154 } 155 urlPath = strings.ReplaceAll(urlPath, "{firewallPolicyName}", url.PathEscape(firewallPolicyName)) 156 if client.subscriptionID == "" { 157 return nil, errors.New("parameter client.subscriptionID cannot be empty") 158 } 159 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 160 req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 161 if err != nil { 162 return nil, err 163 } 164 reqQP := req.Raw().URL.Query() 165 reqQP.Set("api-version", "2024-05-01") 166 req.Raw().URL.RawQuery = reqQP.Encode() 167 req.Raw().Header["Accept"] = []string{"application/json"} 168 return req, nil 169 } 170 171 // Get - Get a draft Firewall Policy. 172 // If the operation fails it returns an *azcore.ResponseError type. 173 // 174 // Generated from API version 2024-05-01 175 // - resourceGroupName - The name of the resource group. 176 // - firewallPolicyName - The name of the Firewall Policy. 177 // - options - FirewallPolicyDraftsClientGetOptions contains the optional parameters for the FirewallPolicyDraftsClient.Get 178 // method. 179 func (client *FirewallPolicyDraftsClient) Get(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *FirewallPolicyDraftsClientGetOptions) (FirewallPolicyDraftsClientGetResponse, error) { 180 var err error 181 const operationName = "FirewallPolicyDraftsClient.Get" 182 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 183 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 184 defer func() { endSpan(err) }() 185 req, err := client.getCreateRequest(ctx, resourceGroupName, firewallPolicyName, options) 186 if err != nil { 187 return FirewallPolicyDraftsClientGetResponse{}, err 188 } 189 httpResp, err := client.internal.Pipeline().Do(req) 190 if err != nil { 191 return FirewallPolicyDraftsClientGetResponse{}, err 192 } 193 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 194 err = runtime.NewResponseError(httpResp) 195 return FirewallPolicyDraftsClientGetResponse{}, err 196 } 197 resp, err := client.getHandleResponse(httpResp) 198 return resp, err 199 } 200 201 // getCreateRequest creates the Get request. 202 func (client *FirewallPolicyDraftsClient) getCreateRequest(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *FirewallPolicyDraftsClientGetOptions) (*policy.Request, error) { 203 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/firewallPolicies/{firewallPolicyName}/firewallPolicyDrafts/default" 204 if resourceGroupName == "" { 205 return nil, errors.New("parameter resourceGroupName cannot be empty") 206 } 207 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 208 if firewallPolicyName == "" { 209 return nil, errors.New("parameter firewallPolicyName cannot be empty") 210 } 211 urlPath = strings.ReplaceAll(urlPath, "{firewallPolicyName}", url.PathEscape(firewallPolicyName)) 212 if client.subscriptionID == "" { 213 return nil, errors.New("parameter client.subscriptionID cannot be empty") 214 } 215 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 216 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 217 if err != nil { 218 return nil, err 219 } 220 reqQP := req.Raw().URL.Query() 221 reqQP.Set("api-version", "2024-05-01") 222 req.Raw().URL.RawQuery = reqQP.Encode() 223 req.Raw().Header["Accept"] = []string{"application/json"} 224 return req, nil 225 } 226 227 // getHandleResponse handles the Get response. 228 func (client *FirewallPolicyDraftsClient) getHandleResponse(resp *http.Response) (FirewallPolicyDraftsClientGetResponse, error) { 229 result := FirewallPolicyDraftsClientGetResponse{} 230 if err := runtime.UnmarshalAsJSON(resp, &result.FirewallPolicyDraft); err != nil { 231 return FirewallPolicyDraftsClientGetResponse{}, err 232 } 233 return result, nil 234 }