github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/dscpconfiguration_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 // DscpConfigurationClient contains the methods for the DscpConfiguration group. 24 // Don't use this type directly, use NewDscpConfigurationClient() instead. 25 type DscpConfigurationClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewDscpConfigurationClient creates a new instance of DscpConfigurationClient 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 NewDscpConfigurationClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*DscpConfigurationClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &DscpConfigurationClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // BeginCreateOrUpdate - Creates or updates a DSCP Configuration. 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 // - dscpConfigurationName - The name of the resource. 53 // - parameters - Parameters supplied to the create or update dscp configuration operation. 54 // - options - DscpConfigurationClientBeginCreateOrUpdateOptions contains the optional parameters for the DscpConfigurationClient.BeginCreateOrUpdate 55 // method. 56 func (client *DscpConfigurationClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, dscpConfigurationName string, parameters DscpConfiguration, options *DscpConfigurationClientBeginCreateOrUpdateOptions) (*runtime.Poller[DscpConfigurationClientCreateOrUpdateResponse], error) { 57 if options == nil || options.ResumeToken == "" { 58 resp, err := client.createOrUpdate(ctx, resourceGroupName, dscpConfigurationName, parameters, options) 59 if err != nil { 60 return nil, err 61 } 62 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DscpConfigurationClientCreateOrUpdateResponse]{ 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[DscpConfigurationClientCreateOrUpdateResponse]{ 69 Tracer: client.internal.Tracer(), 70 }) 71 } 72 } 73 74 // CreateOrUpdate - Creates or updates a DSCP Configuration. 75 // If the operation fails it returns an *azcore.ResponseError type. 76 // 77 // Generated from API version 2024-05-01 78 func (client *DscpConfigurationClient) createOrUpdate(ctx context.Context, resourceGroupName string, dscpConfigurationName string, parameters DscpConfiguration, options *DscpConfigurationClientBeginCreateOrUpdateOptions) (*http.Response, error) { 79 var err error 80 const operationName = "DscpConfigurationClient.BeginCreateOrUpdate" 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.createOrUpdateCreateRequest(ctx, resourceGroupName, dscpConfigurationName, 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.StatusCreated) { 93 err = runtime.NewResponseError(httpResp) 94 return nil, err 95 } 96 return httpResp, nil 97 } 98 99 // createOrUpdateCreateRequest creates the CreateOrUpdate request. 100 func (client *DscpConfigurationClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, dscpConfigurationName string, parameters DscpConfiguration, options *DscpConfigurationClientBeginCreateOrUpdateOptions) (*policy.Request, error) { 101 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/dscpConfigurations/{dscpConfigurationName}" 102 if resourceGroupName == "" { 103 return nil, errors.New("parameter resourceGroupName cannot be empty") 104 } 105 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 106 if dscpConfigurationName == "" { 107 return nil, errors.New("parameter dscpConfigurationName cannot be empty") 108 } 109 urlPath = strings.ReplaceAll(urlPath, "{dscpConfigurationName}", url.PathEscape(dscpConfigurationName)) 110 if client.subscriptionID == "" { 111 return nil, errors.New("parameter client.subscriptionID cannot be empty") 112 } 113 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 114 req, err := runtime.NewRequest(ctx, http.MethodPut, 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 } 127 128 // BeginDelete - Deletes a DSCP Configuration. 129 // If the operation fails it returns an *azcore.ResponseError type. 130 // 131 // Generated from API version 2024-05-01 132 // - resourceGroupName - The name of the resource group. 133 // - dscpConfigurationName - The name of the resource. 134 // - options - DscpConfigurationClientBeginDeleteOptions contains the optional parameters for the DscpConfigurationClient.BeginDelete 135 // method. 136 func (client *DscpConfigurationClient) BeginDelete(ctx context.Context, resourceGroupName string, dscpConfigurationName string, options *DscpConfigurationClientBeginDeleteOptions) (*runtime.Poller[DscpConfigurationClientDeleteResponse], error) { 137 if options == nil || options.ResumeToken == "" { 138 resp, err := client.deleteOperation(ctx, resourceGroupName, dscpConfigurationName, options) 139 if err != nil { 140 return nil, err 141 } 142 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[DscpConfigurationClientDeleteResponse]{ 143 FinalStateVia: runtime.FinalStateViaLocation, 144 Tracer: client.internal.Tracer(), 145 }) 146 return poller, err 147 } else { 148 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[DscpConfigurationClientDeleteResponse]{ 149 Tracer: client.internal.Tracer(), 150 }) 151 } 152 } 153 154 // Delete - Deletes a DSCP Configuration. 155 // If the operation fails it returns an *azcore.ResponseError type. 156 // 157 // Generated from API version 2024-05-01 158 func (client *DscpConfigurationClient) deleteOperation(ctx context.Context, resourceGroupName string, dscpConfigurationName string, options *DscpConfigurationClientBeginDeleteOptions) (*http.Response, error) { 159 var err error 160 const operationName = "DscpConfigurationClient.BeginDelete" 161 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 162 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 163 defer func() { endSpan(err) }() 164 req, err := client.deleteCreateRequest(ctx, resourceGroupName, dscpConfigurationName, options) 165 if err != nil { 166 return nil, err 167 } 168 httpResp, err := client.internal.Pipeline().Do(req) 169 if err != nil { 170 return nil, err 171 } 172 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 173 err = runtime.NewResponseError(httpResp) 174 return nil, err 175 } 176 return httpResp, nil 177 } 178 179 // deleteCreateRequest creates the Delete request. 180 func (client *DscpConfigurationClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, dscpConfigurationName string, options *DscpConfigurationClientBeginDeleteOptions) (*policy.Request, error) { 181 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/dscpConfigurations/{dscpConfigurationName}" 182 if resourceGroupName == "" { 183 return nil, errors.New("parameter resourceGroupName cannot be empty") 184 } 185 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 186 if dscpConfigurationName == "" { 187 return nil, errors.New("parameter dscpConfigurationName cannot be empty") 188 } 189 urlPath = strings.ReplaceAll(urlPath, "{dscpConfigurationName}", url.PathEscape(dscpConfigurationName)) 190 if client.subscriptionID == "" { 191 return nil, errors.New("parameter client.subscriptionID cannot be empty") 192 } 193 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 194 req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 195 if err != nil { 196 return nil, err 197 } 198 reqQP := req.Raw().URL.Query() 199 reqQP.Set("api-version", "2024-05-01") 200 req.Raw().URL.RawQuery = reqQP.Encode() 201 req.Raw().Header["Accept"] = []string{"application/json"} 202 return req, nil 203 } 204 205 // Get - Gets a DSCP Configuration. 206 // If the operation fails it returns an *azcore.ResponseError type. 207 // 208 // Generated from API version 2024-05-01 209 // - resourceGroupName - The name of the resource group. 210 // - dscpConfigurationName - The name of the resource. 211 // - options - DscpConfigurationClientGetOptions contains the optional parameters for the DscpConfigurationClient.Get method. 212 func (client *DscpConfigurationClient) Get(ctx context.Context, resourceGroupName string, dscpConfigurationName string, options *DscpConfigurationClientGetOptions) (DscpConfigurationClientGetResponse, error) { 213 var err error 214 const operationName = "DscpConfigurationClient.Get" 215 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 216 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 217 defer func() { endSpan(err) }() 218 req, err := client.getCreateRequest(ctx, resourceGroupName, dscpConfigurationName, options) 219 if err != nil { 220 return DscpConfigurationClientGetResponse{}, err 221 } 222 httpResp, err := client.internal.Pipeline().Do(req) 223 if err != nil { 224 return DscpConfigurationClientGetResponse{}, err 225 } 226 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 227 err = runtime.NewResponseError(httpResp) 228 return DscpConfigurationClientGetResponse{}, err 229 } 230 resp, err := client.getHandleResponse(httpResp) 231 return resp, err 232 } 233 234 // getCreateRequest creates the Get request. 235 func (client *DscpConfigurationClient) getCreateRequest(ctx context.Context, resourceGroupName string, dscpConfigurationName string, options *DscpConfigurationClientGetOptions) (*policy.Request, error) { 236 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/dscpConfigurations/{dscpConfigurationName}" 237 if resourceGroupName == "" { 238 return nil, errors.New("parameter resourceGroupName cannot be empty") 239 } 240 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 241 if dscpConfigurationName == "" { 242 return nil, errors.New("parameter dscpConfigurationName cannot be empty") 243 } 244 urlPath = strings.ReplaceAll(urlPath, "{dscpConfigurationName}", url.PathEscape(dscpConfigurationName)) 245 if client.subscriptionID == "" { 246 return nil, errors.New("parameter client.subscriptionID cannot be empty") 247 } 248 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 249 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 250 if err != nil { 251 return nil, err 252 } 253 reqQP := req.Raw().URL.Query() 254 reqQP.Set("api-version", "2024-05-01") 255 req.Raw().URL.RawQuery = reqQP.Encode() 256 req.Raw().Header["Accept"] = []string{"application/json"} 257 return req, nil 258 } 259 260 // getHandleResponse handles the Get response. 261 func (client *DscpConfigurationClient) getHandleResponse(resp *http.Response) (DscpConfigurationClientGetResponse, error) { 262 result := DscpConfigurationClientGetResponse{} 263 if err := runtime.UnmarshalAsJSON(resp, &result.DscpConfiguration); err != nil { 264 return DscpConfigurationClientGetResponse{}, err 265 } 266 return result, nil 267 } 268 269 // NewListPager - Gets a DSCP Configuration. 270 // 271 // Generated from API version 2024-05-01 272 // - resourceGroupName - The name of the resource group. 273 // - options - DscpConfigurationClientListOptions contains the optional parameters for the DscpConfigurationClient.NewListPager 274 // method. 275 func (client *DscpConfigurationClient) NewListPager(resourceGroupName string, options *DscpConfigurationClientListOptions) *runtime.Pager[DscpConfigurationClientListResponse] { 276 return runtime.NewPager(runtime.PagingHandler[DscpConfigurationClientListResponse]{ 277 More: func(page DscpConfigurationClientListResponse) bool { 278 return page.NextLink != nil && len(*page.NextLink) > 0 279 }, 280 Fetcher: func(ctx context.Context, page *DscpConfigurationClientListResponse) (DscpConfigurationClientListResponse, error) { 281 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DscpConfigurationClient.NewListPager") 282 nextLink := "" 283 if page != nil { 284 nextLink = *page.NextLink 285 } 286 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 287 return client.listCreateRequest(ctx, resourceGroupName, options) 288 }, nil) 289 if err != nil { 290 return DscpConfigurationClientListResponse{}, err 291 } 292 return client.listHandleResponse(resp) 293 }, 294 Tracer: client.internal.Tracer(), 295 }) 296 } 297 298 // listCreateRequest creates the List request. 299 func (client *DscpConfigurationClient) listCreateRequest(ctx context.Context, resourceGroupName string, options *DscpConfigurationClientListOptions) (*policy.Request, error) { 300 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/dscpConfigurations" 301 if resourceGroupName == "" { 302 return nil, errors.New("parameter resourceGroupName cannot be empty") 303 } 304 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 305 if client.subscriptionID == "" { 306 return nil, errors.New("parameter client.subscriptionID cannot be empty") 307 } 308 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 309 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 310 if err != nil { 311 return nil, err 312 } 313 reqQP := req.Raw().URL.Query() 314 reqQP.Set("api-version", "2024-05-01") 315 req.Raw().URL.RawQuery = reqQP.Encode() 316 req.Raw().Header["Accept"] = []string{"application/json"} 317 return req, nil 318 } 319 320 // listHandleResponse handles the List response. 321 func (client *DscpConfigurationClient) listHandleResponse(resp *http.Response) (DscpConfigurationClientListResponse, error) { 322 result := DscpConfigurationClientListResponse{} 323 if err := runtime.UnmarshalAsJSON(resp, &result.DscpConfigurationListResult); err != nil { 324 return DscpConfigurationClientListResponse{}, err 325 } 326 return result, nil 327 } 328 329 // NewListAllPager - Gets all dscp configurations in a subscription. 330 // 331 // Generated from API version 2024-05-01 332 // - options - DscpConfigurationClientListAllOptions contains the optional parameters for the DscpConfigurationClient.NewListAllPager 333 // method. 334 func (client *DscpConfigurationClient) NewListAllPager(options *DscpConfigurationClientListAllOptions) *runtime.Pager[DscpConfigurationClientListAllResponse] { 335 return runtime.NewPager(runtime.PagingHandler[DscpConfigurationClientListAllResponse]{ 336 More: func(page DscpConfigurationClientListAllResponse) bool { 337 return page.NextLink != nil && len(*page.NextLink) > 0 338 }, 339 Fetcher: func(ctx context.Context, page *DscpConfigurationClientListAllResponse) (DscpConfigurationClientListAllResponse, error) { 340 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DscpConfigurationClient.NewListAllPager") 341 nextLink := "" 342 if page != nil { 343 nextLink = *page.NextLink 344 } 345 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 346 return client.listAllCreateRequest(ctx, options) 347 }, nil) 348 if err != nil { 349 return DscpConfigurationClientListAllResponse{}, err 350 } 351 return client.listAllHandleResponse(resp) 352 }, 353 Tracer: client.internal.Tracer(), 354 }) 355 } 356 357 // listAllCreateRequest creates the ListAll request. 358 func (client *DscpConfigurationClient) listAllCreateRequest(ctx context.Context, options *DscpConfigurationClientListAllOptions) (*policy.Request, error) { 359 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/dscpConfigurations" 360 if client.subscriptionID == "" { 361 return nil, errors.New("parameter client.subscriptionID cannot be empty") 362 } 363 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 364 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 365 if err != nil { 366 return nil, err 367 } 368 reqQP := req.Raw().URL.Query() 369 reqQP.Set("api-version", "2024-05-01") 370 req.Raw().URL.RawQuery = reqQP.Encode() 371 req.Raw().Header["Accept"] = []string{"application/json"} 372 return req, nil 373 } 374 375 // listAllHandleResponse handles the ListAll response. 376 func (client *DscpConfigurationClient) listAllHandleResponse(resp *http.Response) (DscpConfigurationClientListAllResponse, error) { 377 result := DscpConfigurationClientListAllResponse{} 378 if err := runtime.UnmarshalAsJSON(resp, &result.DscpConfigurationListResult); err != nil { 379 return DscpConfigurationClientListAllResponse{}, err 380 } 381 return result, nil 382 }