github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/securityuserrules_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 "strconv" 21 "strings" 22 ) 23 24 // SecurityUserRulesClient contains the methods for the SecurityUserRules group. 25 // Don't use this type directly, use NewSecurityUserRulesClient() instead. 26 type SecurityUserRulesClient struct { 27 internal *arm.Client 28 subscriptionID string 29 } 30 31 // NewSecurityUserRulesClient creates a new instance of SecurityUserRulesClient with the specified values. 32 // - subscriptionID - The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription 33 // ID forms part of the URI for every service call. 34 // - credential - used to authorize requests. Usually a credential from azidentity. 35 // - options - pass nil to accept the default values. 36 func NewSecurityUserRulesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*SecurityUserRulesClient, error) { 37 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 38 if err != nil { 39 return nil, err 40 } 41 client := &SecurityUserRulesClient{ 42 subscriptionID: subscriptionID, 43 internal: cl, 44 } 45 return client, nil 46 } 47 48 // CreateOrUpdate - Creates or updates a security user rule. 49 // If the operation fails it returns an *azcore.ResponseError type. 50 // 51 // Generated from API version 2024-05-01 52 // - resourceGroupName - The name of the resource group. The name is case insensitive. 53 // - networkManagerName - The name of the network manager. 54 // - configurationName - The name of the network manager Security Configuration. 55 // - ruleCollectionName - The name of the network manager security Configuration rule collection. 56 // - ruleName - The name of the rule. 57 // - securityUserRule - The security user rule to create or update 58 // - options - SecurityUserRulesClientCreateOrUpdateOptions contains the optional parameters for the SecurityUserRulesClient.CreateOrUpdate 59 // method. 60 func (client *SecurityUserRulesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleName string, securityUserRule SecurityUserRule, options *SecurityUserRulesClientCreateOrUpdateOptions) (SecurityUserRulesClientCreateOrUpdateResponse, error) { 61 var err error 62 const operationName = "SecurityUserRulesClient.CreateOrUpdate" 63 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 64 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 65 defer func() { endSpan(err) }() 66 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, networkManagerName, configurationName, ruleCollectionName, ruleName, securityUserRule, options) 67 if err != nil { 68 return SecurityUserRulesClientCreateOrUpdateResponse{}, err 69 } 70 httpResp, err := client.internal.Pipeline().Do(req) 71 if err != nil { 72 return SecurityUserRulesClientCreateOrUpdateResponse{}, err 73 } 74 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { 75 err = runtime.NewResponseError(httpResp) 76 return SecurityUserRulesClientCreateOrUpdateResponse{}, err 77 } 78 resp, err := client.createOrUpdateHandleResponse(httpResp) 79 return resp, err 80 } 81 82 // createOrUpdateCreateRequest creates the CreateOrUpdate request. 83 func (client *SecurityUserRulesClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleName string, securityUserRule SecurityUserRule, options *SecurityUserRulesClientCreateOrUpdateOptions) (*policy.Request, error) { 84 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/securityUserConfigurations/{configurationName}/ruleCollections/{ruleCollectionName}/rules/{ruleName}" 85 if client.subscriptionID == "" { 86 return nil, errors.New("parameter client.subscriptionID cannot be empty") 87 } 88 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 89 if resourceGroupName == "" { 90 return nil, errors.New("parameter resourceGroupName cannot be empty") 91 } 92 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 93 if networkManagerName == "" { 94 return nil, errors.New("parameter networkManagerName cannot be empty") 95 } 96 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 97 if configurationName == "" { 98 return nil, errors.New("parameter configurationName cannot be empty") 99 } 100 urlPath = strings.ReplaceAll(urlPath, "{configurationName}", url.PathEscape(configurationName)) 101 if ruleCollectionName == "" { 102 return nil, errors.New("parameter ruleCollectionName cannot be empty") 103 } 104 urlPath = strings.ReplaceAll(urlPath, "{ruleCollectionName}", url.PathEscape(ruleCollectionName)) 105 if ruleName == "" { 106 return nil, errors.New("parameter ruleName cannot be empty") 107 } 108 urlPath = strings.ReplaceAll(urlPath, "{ruleName}", url.PathEscape(ruleName)) 109 req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 110 if err != nil { 111 return nil, err 112 } 113 reqQP := req.Raw().URL.Query() 114 reqQP.Set("api-version", "2024-05-01") 115 req.Raw().URL.RawQuery = reqQP.Encode() 116 req.Raw().Header["Accept"] = []string{"application/json"} 117 if err := runtime.MarshalAsJSON(req, securityUserRule); err != nil { 118 return nil, err 119 } 120 return req, nil 121 } 122 123 // createOrUpdateHandleResponse handles the CreateOrUpdate response. 124 func (client *SecurityUserRulesClient) createOrUpdateHandleResponse(resp *http.Response) (SecurityUserRulesClientCreateOrUpdateResponse, error) { 125 result := SecurityUserRulesClientCreateOrUpdateResponse{} 126 if err := runtime.UnmarshalAsJSON(resp, &result.SecurityUserRule); err != nil { 127 return SecurityUserRulesClientCreateOrUpdateResponse{}, err 128 } 129 return result, nil 130 } 131 132 // BeginDelete - Deletes a security user rule. 133 // If the operation fails it returns an *azcore.ResponseError type. 134 // 135 // Generated from API version 2024-05-01 136 // - resourceGroupName - The name of the resource group. The name is case insensitive. 137 // - networkManagerName - The name of the network manager. 138 // - configurationName - The name of the network manager Security Configuration. 139 // - ruleCollectionName - The name of the network manager security Configuration rule collection. 140 // - ruleName - The name of the rule. 141 // - options - SecurityUserRulesClientBeginDeleteOptions contains the optional parameters for the SecurityUserRulesClient.BeginDelete 142 // method. 143 func (client *SecurityUserRulesClient) BeginDelete(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleName string, options *SecurityUserRulesClientBeginDeleteOptions) (*runtime.Poller[SecurityUserRulesClientDeleteResponse], error) { 144 if options == nil || options.ResumeToken == "" { 145 resp, err := client.deleteOperation(ctx, resourceGroupName, networkManagerName, configurationName, ruleCollectionName, ruleName, options) 146 if err != nil { 147 return nil, err 148 } 149 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[SecurityUserRulesClientDeleteResponse]{ 150 FinalStateVia: runtime.FinalStateViaLocation, 151 Tracer: client.internal.Tracer(), 152 }) 153 return poller, err 154 } else { 155 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[SecurityUserRulesClientDeleteResponse]{ 156 Tracer: client.internal.Tracer(), 157 }) 158 } 159 } 160 161 // Delete - Deletes a security user rule. 162 // If the operation fails it returns an *azcore.ResponseError type. 163 // 164 // Generated from API version 2024-05-01 165 func (client *SecurityUserRulesClient) deleteOperation(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleName string, options *SecurityUserRulesClientBeginDeleteOptions) (*http.Response, error) { 166 var err error 167 const operationName = "SecurityUserRulesClient.BeginDelete" 168 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 169 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 170 defer func() { endSpan(err) }() 171 req, err := client.deleteCreateRequest(ctx, resourceGroupName, networkManagerName, configurationName, ruleCollectionName, ruleName, options) 172 if err != nil { 173 return nil, err 174 } 175 httpResp, err := client.internal.Pipeline().Do(req) 176 if err != nil { 177 return nil, err 178 } 179 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 180 err = runtime.NewResponseError(httpResp) 181 return nil, err 182 } 183 return httpResp, nil 184 } 185 186 // deleteCreateRequest creates the Delete request. 187 func (client *SecurityUserRulesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleName string, options *SecurityUserRulesClientBeginDeleteOptions) (*policy.Request, error) { 188 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/securityUserConfigurations/{configurationName}/ruleCollections/{ruleCollectionName}/rules/{ruleName}" 189 if client.subscriptionID == "" { 190 return nil, errors.New("parameter client.subscriptionID cannot be empty") 191 } 192 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 193 if resourceGroupName == "" { 194 return nil, errors.New("parameter resourceGroupName cannot be empty") 195 } 196 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 197 if networkManagerName == "" { 198 return nil, errors.New("parameter networkManagerName cannot be empty") 199 } 200 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 201 if configurationName == "" { 202 return nil, errors.New("parameter configurationName cannot be empty") 203 } 204 urlPath = strings.ReplaceAll(urlPath, "{configurationName}", url.PathEscape(configurationName)) 205 if ruleCollectionName == "" { 206 return nil, errors.New("parameter ruleCollectionName cannot be empty") 207 } 208 urlPath = strings.ReplaceAll(urlPath, "{ruleCollectionName}", url.PathEscape(ruleCollectionName)) 209 if ruleName == "" { 210 return nil, errors.New("parameter ruleName cannot be empty") 211 } 212 urlPath = strings.ReplaceAll(urlPath, "{ruleName}", url.PathEscape(ruleName)) 213 req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 214 if err != nil { 215 return nil, err 216 } 217 reqQP := req.Raw().URL.Query() 218 reqQP.Set("api-version", "2024-05-01") 219 if options != nil && options.Force != nil { 220 reqQP.Set("force", strconv.FormatBool(*options.Force)) 221 } 222 req.Raw().URL.RawQuery = reqQP.Encode() 223 req.Raw().Header["Accept"] = []string{"application/json"} 224 return req, nil 225 } 226 227 // Get - Gets a security user rule. 228 // If the operation fails it returns an *azcore.ResponseError type. 229 // 230 // Generated from API version 2024-05-01 231 // - resourceGroupName - The name of the resource group. The name is case insensitive. 232 // - networkManagerName - The name of the network manager. 233 // - configurationName - The name of the network manager Security Configuration. 234 // - ruleCollectionName - The name of the network manager security Configuration rule collection. 235 // - ruleName - The name of the rule. 236 // - options - SecurityUserRulesClientGetOptions contains the optional parameters for the SecurityUserRulesClient.Get method. 237 func (client *SecurityUserRulesClient) Get(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleName string, options *SecurityUserRulesClientGetOptions) (SecurityUserRulesClientGetResponse, error) { 238 var err error 239 const operationName = "SecurityUserRulesClient.Get" 240 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 241 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 242 defer func() { endSpan(err) }() 243 req, err := client.getCreateRequest(ctx, resourceGroupName, networkManagerName, configurationName, ruleCollectionName, ruleName, options) 244 if err != nil { 245 return SecurityUserRulesClientGetResponse{}, err 246 } 247 httpResp, err := client.internal.Pipeline().Do(req) 248 if err != nil { 249 return SecurityUserRulesClientGetResponse{}, err 250 } 251 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 252 err = runtime.NewResponseError(httpResp) 253 return SecurityUserRulesClientGetResponse{}, err 254 } 255 resp, err := client.getHandleResponse(httpResp) 256 return resp, err 257 } 258 259 // getCreateRequest creates the Get request. 260 func (client *SecurityUserRulesClient) getCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, ruleName string, options *SecurityUserRulesClientGetOptions) (*policy.Request, error) { 261 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/securityUserConfigurations/{configurationName}/ruleCollections/{ruleCollectionName}/rules/{ruleName}" 262 if client.subscriptionID == "" { 263 return nil, errors.New("parameter client.subscriptionID cannot be empty") 264 } 265 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 266 if resourceGroupName == "" { 267 return nil, errors.New("parameter resourceGroupName cannot be empty") 268 } 269 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 270 if networkManagerName == "" { 271 return nil, errors.New("parameter networkManagerName cannot be empty") 272 } 273 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 274 if configurationName == "" { 275 return nil, errors.New("parameter configurationName cannot be empty") 276 } 277 urlPath = strings.ReplaceAll(urlPath, "{configurationName}", url.PathEscape(configurationName)) 278 if ruleCollectionName == "" { 279 return nil, errors.New("parameter ruleCollectionName cannot be empty") 280 } 281 urlPath = strings.ReplaceAll(urlPath, "{ruleCollectionName}", url.PathEscape(ruleCollectionName)) 282 if ruleName == "" { 283 return nil, errors.New("parameter ruleName cannot be empty") 284 } 285 urlPath = strings.ReplaceAll(urlPath, "{ruleName}", url.PathEscape(ruleName)) 286 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 287 if err != nil { 288 return nil, err 289 } 290 reqQP := req.Raw().URL.Query() 291 reqQP.Set("api-version", "2024-05-01") 292 req.Raw().URL.RawQuery = reqQP.Encode() 293 req.Raw().Header["Accept"] = []string{"application/json"} 294 return req, nil 295 } 296 297 // getHandleResponse handles the Get response. 298 func (client *SecurityUserRulesClient) getHandleResponse(resp *http.Response) (SecurityUserRulesClientGetResponse, error) { 299 result := SecurityUserRulesClientGetResponse{} 300 if err := runtime.UnmarshalAsJSON(resp, &result.SecurityUserRule); err != nil { 301 return SecurityUserRulesClientGetResponse{}, err 302 } 303 return result, nil 304 } 305 306 // NewListPager - Lists all Security User Rules in a rule collection. 307 // 308 // Generated from API version 2024-05-01 309 // - resourceGroupName - The name of the resource group. The name is case insensitive. 310 // - networkManagerName - The name of the network manager. 311 // - configurationName - The name of the network manager Security Configuration. 312 // - ruleCollectionName - The name of the network manager security Configuration rule collection. 313 // - options - SecurityUserRulesClientListOptions contains the optional parameters for the SecurityUserRulesClient.NewListPager 314 // method. 315 func (client *SecurityUserRulesClient) NewListPager(resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, options *SecurityUserRulesClientListOptions) *runtime.Pager[SecurityUserRulesClientListResponse] { 316 return runtime.NewPager(runtime.PagingHandler[SecurityUserRulesClientListResponse]{ 317 More: func(page SecurityUserRulesClientListResponse) bool { 318 return page.NextLink != nil && len(*page.NextLink) > 0 319 }, 320 Fetcher: func(ctx context.Context, page *SecurityUserRulesClientListResponse) (SecurityUserRulesClientListResponse, error) { 321 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "SecurityUserRulesClient.NewListPager") 322 nextLink := "" 323 if page != nil { 324 nextLink = *page.NextLink 325 } 326 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 327 return client.listCreateRequest(ctx, resourceGroupName, networkManagerName, configurationName, ruleCollectionName, options) 328 }, nil) 329 if err != nil { 330 return SecurityUserRulesClientListResponse{}, err 331 } 332 return client.listHandleResponse(resp) 333 }, 334 Tracer: client.internal.Tracer(), 335 }) 336 } 337 338 // listCreateRequest creates the List request. 339 func (client *SecurityUserRulesClient) listCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, configurationName string, ruleCollectionName string, options *SecurityUserRulesClientListOptions) (*policy.Request, error) { 340 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/securityUserConfigurations/{configurationName}/ruleCollections/{ruleCollectionName}/rules" 341 if client.subscriptionID == "" { 342 return nil, errors.New("parameter client.subscriptionID cannot be empty") 343 } 344 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 345 if resourceGroupName == "" { 346 return nil, errors.New("parameter resourceGroupName cannot be empty") 347 } 348 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 349 if networkManagerName == "" { 350 return nil, errors.New("parameter networkManagerName cannot be empty") 351 } 352 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 353 if configurationName == "" { 354 return nil, errors.New("parameter configurationName cannot be empty") 355 } 356 urlPath = strings.ReplaceAll(urlPath, "{configurationName}", url.PathEscape(configurationName)) 357 if ruleCollectionName == "" { 358 return nil, errors.New("parameter ruleCollectionName cannot be empty") 359 } 360 urlPath = strings.ReplaceAll(urlPath, "{ruleCollectionName}", url.PathEscape(ruleCollectionName)) 361 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 362 if err != nil { 363 return nil, err 364 } 365 reqQP := req.Raw().URL.Query() 366 if options != nil && options.SkipToken != nil { 367 reqQP.Set("$skipToken", *options.SkipToken) 368 } 369 if options != nil && options.Top != nil { 370 reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10)) 371 } 372 reqQP.Set("api-version", "2024-05-01") 373 req.Raw().URL.RawQuery = reqQP.Encode() 374 req.Raw().Header["Accept"] = []string{"application/json"} 375 return req, nil 376 } 377 378 // listHandleResponse handles the List response. 379 func (client *SecurityUserRulesClient) listHandleResponse(resp *http.Response) (SecurityUserRulesClientListResponse, error) { 380 result := SecurityUserRulesClientListResponse{} 381 if err := runtime.UnmarshalAsJSON(resp, &result.SecurityUserRuleListResult); err != nil { 382 return SecurityUserRulesClientListResponse{}, err 383 } 384 return result, nil 385 }