github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/verifierworkspaces_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 // VerifierWorkspacesClient contains the methods for the VerifierWorkspaces group. 25 // Don't use this type directly, use NewVerifierWorkspacesClient() instead. 26 type VerifierWorkspacesClient struct { 27 internal *arm.Client 28 subscriptionID string 29 } 30 31 // NewVerifierWorkspacesClient creates a new instance of VerifierWorkspacesClient 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 NewVerifierWorkspacesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*VerifierWorkspacesClient, error) { 37 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 38 if err != nil { 39 return nil, err 40 } 41 client := &VerifierWorkspacesClient{ 42 subscriptionID: subscriptionID, 43 internal: cl, 44 } 45 return client, nil 46 } 47 48 // Create - Creates Verifier Workspace. 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. 53 // - networkManagerName - The name of the network manager. 54 // - workspaceName - Workspace name. 55 // - body - Verifier Workspace object to create/update. 56 // - options - VerifierWorkspacesClientCreateOptions contains the optional parameters for the VerifierWorkspacesClient.Create 57 // method. 58 func (client *VerifierWorkspacesClient) Create(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, body VerifierWorkspace, options *VerifierWorkspacesClientCreateOptions) (VerifierWorkspacesClientCreateResponse, error) { 59 var err error 60 const operationName = "VerifierWorkspacesClient.Create" 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.createCreateRequest(ctx, resourceGroupName, networkManagerName, workspaceName, body, options) 65 if err != nil { 66 return VerifierWorkspacesClientCreateResponse{}, err 67 } 68 httpResp, err := client.internal.Pipeline().Do(req) 69 if err != nil { 70 return VerifierWorkspacesClientCreateResponse{}, err 71 } 72 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { 73 err = runtime.NewResponseError(httpResp) 74 return VerifierWorkspacesClientCreateResponse{}, err 75 } 76 resp, err := client.createHandleResponse(httpResp) 77 return resp, err 78 } 79 80 // createCreateRequest creates the Create request. 81 func (client *VerifierWorkspacesClient) createCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, body VerifierWorkspace, options *VerifierWorkspacesClientCreateOptions) (*policy.Request, error) { 82 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/verifierWorkspaces/{workspaceName}" 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 workspaceName == "" { 96 return nil, errors.New("parameter workspaceName cannot be empty") 97 } 98 urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName)) 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, body); err != nil { 108 return nil, err 109 } 110 return req, nil 111 } 112 113 // createHandleResponse handles the Create response. 114 func (client *VerifierWorkspacesClient) createHandleResponse(resp *http.Response) (VerifierWorkspacesClientCreateResponse, error) { 115 result := VerifierWorkspacesClientCreateResponse{} 116 if err := runtime.UnmarshalAsJSON(resp, &result.VerifierWorkspace); err != nil { 117 return VerifierWorkspacesClientCreateResponse{}, err 118 } 119 return result, nil 120 } 121 122 // BeginDelete - Deletes Verifier Workspace. 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. 127 // - networkManagerName - The name of the network manager. 128 // - workspaceName - Workspace name. 129 // - options - VerifierWorkspacesClientBeginDeleteOptions contains the optional parameters for the VerifierWorkspacesClient.BeginDelete 130 // method. 131 func (client *VerifierWorkspacesClient) BeginDelete(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, options *VerifierWorkspacesClientBeginDeleteOptions) (*runtime.Poller[VerifierWorkspacesClientDeleteResponse], error) { 132 if options == nil || options.ResumeToken == "" { 133 resp, err := client.deleteOperation(ctx, resourceGroupName, networkManagerName, workspaceName, options) 134 if err != nil { 135 return nil, err 136 } 137 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[VerifierWorkspacesClientDeleteResponse]{ 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[VerifierWorkspacesClientDeleteResponse]{ 144 Tracer: client.internal.Tracer(), 145 }) 146 } 147 } 148 149 // Delete - Deletes Verifier Workspace. 150 // If the operation fails it returns an *azcore.ResponseError type. 151 // 152 // Generated from API version 2024-05-01 153 func (client *VerifierWorkspacesClient) deleteOperation(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, options *VerifierWorkspacesClientBeginDeleteOptions) (*http.Response, error) { 154 var err error 155 const operationName = "VerifierWorkspacesClient.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, workspaceName, 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.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 *VerifierWorkspacesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, options *VerifierWorkspacesClientBeginDeleteOptions) (*policy.Request, error) { 176 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/verifierWorkspaces/{workspaceName}" 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 workspaceName == "" { 190 return nil, errors.New("parameter workspaceName cannot be empty") 191 } 192 urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName)) 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 req.Raw().URL.RawQuery = reqQP.Encode() 200 req.Raw().Header["Accept"] = []string{"application/json"} 201 return req, nil 202 } 203 204 // Get - Gets Verifier Workspace. 205 // If the operation fails it returns an *azcore.ResponseError type. 206 // 207 // Generated from API version 2024-05-01 208 // - resourceGroupName - The name of the resource group. 209 // - networkManagerName - The name of the network manager. 210 // - workspaceName - Workspace name. 211 // - options - VerifierWorkspacesClientGetOptions contains the optional parameters for the VerifierWorkspacesClient.Get method. 212 func (client *VerifierWorkspacesClient) Get(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, options *VerifierWorkspacesClientGetOptions) (VerifierWorkspacesClientGetResponse, error) { 213 var err error 214 const operationName = "VerifierWorkspacesClient.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, networkManagerName, workspaceName, options) 219 if err != nil { 220 return VerifierWorkspacesClientGetResponse{}, err 221 } 222 httpResp, err := client.internal.Pipeline().Do(req) 223 if err != nil { 224 return VerifierWorkspacesClientGetResponse{}, err 225 } 226 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 227 err = runtime.NewResponseError(httpResp) 228 return VerifierWorkspacesClientGetResponse{}, err 229 } 230 resp, err := client.getHandleResponse(httpResp) 231 return resp, err 232 } 233 234 // getCreateRequest creates the Get request. 235 func (client *VerifierWorkspacesClient) getCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, options *VerifierWorkspacesClientGetOptions) (*policy.Request, error) { 236 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/verifierWorkspaces/{workspaceName}" 237 if client.subscriptionID == "" { 238 return nil, errors.New("parameter client.subscriptionID cannot be empty") 239 } 240 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 241 if resourceGroupName == "" { 242 return nil, errors.New("parameter resourceGroupName cannot be empty") 243 } 244 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 245 if networkManagerName == "" { 246 return nil, errors.New("parameter networkManagerName cannot be empty") 247 } 248 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 249 if workspaceName == "" { 250 return nil, errors.New("parameter workspaceName cannot be empty") 251 } 252 urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName)) 253 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 254 if err != nil { 255 return nil, err 256 } 257 reqQP := req.Raw().URL.Query() 258 reqQP.Set("api-version", "2024-05-01") 259 req.Raw().URL.RawQuery = reqQP.Encode() 260 req.Raw().Header["Accept"] = []string{"application/json"} 261 return req, nil 262 } 263 264 // getHandleResponse handles the Get response. 265 func (client *VerifierWorkspacesClient) getHandleResponse(resp *http.Response) (VerifierWorkspacesClientGetResponse, error) { 266 result := VerifierWorkspacesClientGetResponse{} 267 if err := runtime.UnmarshalAsJSON(resp, &result.VerifierWorkspace); err != nil { 268 return VerifierWorkspacesClientGetResponse{}, err 269 } 270 return result, nil 271 } 272 273 // NewListPager - Gets list of Verifier Workspaces. 274 // 275 // Generated from API version 2024-05-01 276 // - resourceGroupName - The name of the resource group. 277 // - networkManagerName - The name of the network manager. 278 // - options - VerifierWorkspacesClientListOptions contains the optional parameters for the VerifierWorkspacesClient.NewListPager 279 // method. 280 func (client *VerifierWorkspacesClient) NewListPager(resourceGroupName string, networkManagerName string, options *VerifierWorkspacesClientListOptions) *runtime.Pager[VerifierWorkspacesClientListResponse] { 281 return runtime.NewPager(runtime.PagingHandler[VerifierWorkspacesClientListResponse]{ 282 More: func(page VerifierWorkspacesClientListResponse) bool { 283 return page.NextLink != nil && len(*page.NextLink) > 0 284 }, 285 Fetcher: func(ctx context.Context, page *VerifierWorkspacesClientListResponse) (VerifierWorkspacesClientListResponse, error) { 286 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "VerifierWorkspacesClient.NewListPager") 287 nextLink := "" 288 if page != nil { 289 nextLink = *page.NextLink 290 } 291 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 292 return client.listCreateRequest(ctx, resourceGroupName, networkManagerName, options) 293 }, nil) 294 if err != nil { 295 return VerifierWorkspacesClientListResponse{}, err 296 } 297 return client.listHandleResponse(resp) 298 }, 299 Tracer: client.internal.Tracer(), 300 }) 301 } 302 303 // listCreateRequest creates the List request. 304 func (client *VerifierWorkspacesClient) listCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, options *VerifierWorkspacesClientListOptions) (*policy.Request, error) { 305 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/verifierWorkspaces" 306 if client.subscriptionID == "" { 307 return nil, errors.New("parameter client.subscriptionID cannot be empty") 308 } 309 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 310 if resourceGroupName == "" { 311 return nil, errors.New("parameter resourceGroupName cannot be empty") 312 } 313 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 314 if networkManagerName == "" { 315 return nil, errors.New("parameter networkManagerName cannot be empty") 316 } 317 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 318 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 319 if err != nil { 320 return nil, err 321 } 322 reqQP := req.Raw().URL.Query() 323 reqQP.Set("api-version", "2024-05-01") 324 if options != nil && options.Skip != nil { 325 reqQP.Set("skip", strconv.FormatInt(int64(*options.Skip), 10)) 326 } 327 if options != nil && options.SkipToken != nil { 328 reqQP.Set("skipToken", *options.SkipToken) 329 } 330 if options != nil && options.SortKey != nil { 331 reqQP.Set("sortKey", *options.SortKey) 332 } 333 if options != nil && options.SortValue != nil { 334 reqQP.Set("sortValue", *options.SortValue) 335 } 336 if options != nil && options.Top != nil { 337 reqQP.Set("top", strconv.FormatInt(int64(*options.Top), 10)) 338 } 339 req.Raw().URL.RawQuery = reqQP.Encode() 340 req.Raw().Header["Accept"] = []string{"application/json"} 341 return req, nil 342 } 343 344 // listHandleResponse handles the List response. 345 func (client *VerifierWorkspacesClient) listHandleResponse(resp *http.Response) (VerifierWorkspacesClientListResponse, error) { 346 result := VerifierWorkspacesClientListResponse{} 347 if err := runtime.UnmarshalAsJSON(resp, &result.VerifierWorkspaceListResult); err != nil { 348 return VerifierWorkspacesClientListResponse{}, err 349 } 350 return result, nil 351 } 352 353 // Update - Updates Verifier Workspace. 354 // If the operation fails it returns an *azcore.ResponseError type. 355 // 356 // Generated from API version 2024-05-01 357 // - resourceGroupName - The name of the resource group. 358 // - networkManagerName - The name of the network manager. 359 // - workspaceName - Workspace name. 360 // - options - VerifierWorkspacesClientUpdateOptions contains the optional parameters for the VerifierWorkspacesClient.Update 361 // method. 362 func (client *VerifierWorkspacesClient) Update(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, options *VerifierWorkspacesClientUpdateOptions) (VerifierWorkspacesClientUpdateResponse, error) { 363 var err error 364 const operationName = "VerifierWorkspacesClient.Update" 365 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 366 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 367 defer func() { endSpan(err) }() 368 req, err := client.updateCreateRequest(ctx, resourceGroupName, networkManagerName, workspaceName, options) 369 if err != nil { 370 return VerifierWorkspacesClientUpdateResponse{}, err 371 } 372 httpResp, err := client.internal.Pipeline().Do(req) 373 if err != nil { 374 return VerifierWorkspacesClientUpdateResponse{}, err 375 } 376 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 377 err = runtime.NewResponseError(httpResp) 378 return VerifierWorkspacesClientUpdateResponse{}, err 379 } 380 resp, err := client.updateHandleResponse(httpResp) 381 return resp, err 382 } 383 384 // updateCreateRequest creates the Update request. 385 func (client *VerifierWorkspacesClient) updateCreateRequest(ctx context.Context, resourceGroupName string, networkManagerName string, workspaceName string, options *VerifierWorkspacesClientUpdateOptions) (*policy.Request, error) { 386 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkManagers/{networkManagerName}/verifierWorkspaces/{workspaceName}" 387 if client.subscriptionID == "" { 388 return nil, errors.New("parameter client.subscriptionID cannot be empty") 389 } 390 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 391 if resourceGroupName == "" { 392 return nil, errors.New("parameter resourceGroupName cannot be empty") 393 } 394 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 395 if networkManagerName == "" { 396 return nil, errors.New("parameter networkManagerName cannot be empty") 397 } 398 urlPath = strings.ReplaceAll(urlPath, "{networkManagerName}", url.PathEscape(networkManagerName)) 399 if workspaceName == "" { 400 return nil, errors.New("parameter workspaceName cannot be empty") 401 } 402 urlPath = strings.ReplaceAll(urlPath, "{workspaceName}", url.PathEscape(workspaceName)) 403 req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 404 if err != nil { 405 return nil, err 406 } 407 reqQP := req.Raw().URL.Query() 408 reqQP.Set("api-version", "2024-05-01") 409 req.Raw().URL.RawQuery = reqQP.Encode() 410 req.Raw().Header["Accept"] = []string{"application/json"} 411 if options != nil && options.Body != nil { 412 if err := runtime.MarshalAsJSON(req, *options.Body); err != nil { 413 return nil, err 414 } 415 return req, nil 416 } 417 return req, nil 418 } 419 420 // updateHandleResponse handles the Update response. 421 func (client *VerifierWorkspacesClient) updateHandleResponse(resp *http.Response) (VerifierWorkspacesClientUpdateResponse, error) { 422 result := VerifierWorkspacesClientUpdateResponse{} 423 if err := runtime.UnmarshalAsJSON(resp, &result.VerifierWorkspace); err != nil { 424 return VerifierWorkspacesClientUpdateResponse{}, err 425 } 426 return result, nil 427 }