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