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