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