github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/firewallpolicyidpssignaturesoverrides_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  // FirewallPolicyIdpsSignaturesOverridesClient contains the methods for the FirewallPolicyIdpsSignaturesOverrides group.
    24  // Don't use this type directly, use NewFirewallPolicyIdpsSignaturesOverridesClient() instead.
    25  type FirewallPolicyIdpsSignaturesOverridesClient struct {
    26  	internal       *arm.Client
    27  	subscriptionID string
    28  }
    29  
    30  // NewFirewallPolicyIdpsSignaturesOverridesClient creates a new instance of FirewallPolicyIdpsSignaturesOverridesClient 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 NewFirewallPolicyIdpsSignaturesOverridesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*FirewallPolicyIdpsSignaturesOverridesClient, error) {
    36  	cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	client := &FirewallPolicyIdpsSignaturesOverridesClient{
    41  		subscriptionID: subscriptionID,
    42  		internal:       cl,
    43  	}
    44  	return client, nil
    45  }
    46  
    47  // Get - Returns all signatures overrides for a specific policy.
    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  //   - firewallPolicyName - The name of the Firewall Policy.
    53  //   - options - FirewallPolicyIdpsSignaturesOverridesClientGetOptions contains the optional parameters for the FirewallPolicyIdpsSignaturesOverridesClient.Get
    54  //     method.
    55  func (client *FirewallPolicyIdpsSignaturesOverridesClient) Get(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *FirewallPolicyIdpsSignaturesOverridesClientGetOptions) (FirewallPolicyIdpsSignaturesOverridesClientGetResponse, error) {
    56  	var err error
    57  	const operationName = "FirewallPolicyIdpsSignaturesOverridesClient.Get"
    58  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
    59  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
    60  	defer func() { endSpan(err) }()
    61  	req, err := client.getCreateRequest(ctx, resourceGroupName, firewallPolicyName, options)
    62  	if err != nil {
    63  		return FirewallPolicyIdpsSignaturesOverridesClientGetResponse{}, err
    64  	}
    65  	httpResp, err := client.internal.Pipeline().Do(req)
    66  	if err != nil {
    67  		return FirewallPolicyIdpsSignaturesOverridesClientGetResponse{}, err
    68  	}
    69  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
    70  		err = runtime.NewResponseError(httpResp)
    71  		return FirewallPolicyIdpsSignaturesOverridesClientGetResponse{}, err
    72  	}
    73  	resp, err := client.getHandleResponse(httpResp)
    74  	return resp, err
    75  }
    76  
    77  // getCreateRequest creates the Get request.
    78  func (client *FirewallPolicyIdpsSignaturesOverridesClient) getCreateRequest(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *FirewallPolicyIdpsSignaturesOverridesClientGetOptions) (*policy.Request, error) {
    79  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/firewallPolicies/{firewallPolicyName}/signatureOverrides/default"
    80  	if resourceGroupName == "" {
    81  		return nil, errors.New("parameter resourceGroupName cannot be empty")
    82  	}
    83  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
    84  	if firewallPolicyName == "" {
    85  		return nil, errors.New("parameter firewallPolicyName cannot be empty")
    86  	}
    87  	urlPath = strings.ReplaceAll(urlPath, "{firewallPolicyName}", url.PathEscape(firewallPolicyName))
    88  	if client.subscriptionID == "" {
    89  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
    90  	}
    91  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
    92  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
    93  	if err != nil {
    94  		return nil, err
    95  	}
    96  	reqQP := req.Raw().URL.Query()
    97  	reqQP.Set("api-version", "2024-05-01")
    98  	req.Raw().URL.RawQuery = reqQP.Encode()
    99  	req.Raw().Header["Accept"] = []string{"application/json"}
   100  	return req, nil
   101  }
   102  
   103  // getHandleResponse handles the Get response.
   104  func (client *FirewallPolicyIdpsSignaturesOverridesClient) getHandleResponse(resp *http.Response) (FirewallPolicyIdpsSignaturesOverridesClientGetResponse, error) {
   105  	result := FirewallPolicyIdpsSignaturesOverridesClientGetResponse{}
   106  	if err := runtime.UnmarshalAsJSON(resp, &result.SignaturesOverrides); err != nil {
   107  		return FirewallPolicyIdpsSignaturesOverridesClientGetResponse{}, err
   108  	}
   109  	return result, nil
   110  }
   111  
   112  // List - Returns all signatures overrides objects for a specific policy as a list containing a single value.
   113  // If the operation fails it returns an *azcore.ResponseError type.
   114  //
   115  // Generated from API version 2024-05-01
   116  //   - resourceGroupName - The name of the resource group.
   117  //   - firewallPolicyName - The name of the Firewall Policy.
   118  //   - options - FirewallPolicyIdpsSignaturesOverridesClientListOptions contains the optional parameters for the FirewallPolicyIdpsSignaturesOverridesClient.List
   119  //     method.
   120  func (client *FirewallPolicyIdpsSignaturesOverridesClient) List(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *FirewallPolicyIdpsSignaturesOverridesClientListOptions) (FirewallPolicyIdpsSignaturesOverridesClientListResponse, error) {
   121  	var err error
   122  	const operationName = "FirewallPolicyIdpsSignaturesOverridesClient.List"
   123  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   124  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   125  	defer func() { endSpan(err) }()
   126  	req, err := client.listCreateRequest(ctx, resourceGroupName, firewallPolicyName, options)
   127  	if err != nil {
   128  		return FirewallPolicyIdpsSignaturesOverridesClientListResponse{}, err
   129  	}
   130  	httpResp, err := client.internal.Pipeline().Do(req)
   131  	if err != nil {
   132  		return FirewallPolicyIdpsSignaturesOverridesClientListResponse{}, err
   133  	}
   134  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
   135  		err = runtime.NewResponseError(httpResp)
   136  		return FirewallPolicyIdpsSignaturesOverridesClientListResponse{}, err
   137  	}
   138  	resp, err := client.listHandleResponse(httpResp)
   139  	return resp, err
   140  }
   141  
   142  // listCreateRequest creates the List request.
   143  func (client *FirewallPolicyIdpsSignaturesOverridesClient) listCreateRequest(ctx context.Context, resourceGroupName string, firewallPolicyName string, options *FirewallPolicyIdpsSignaturesOverridesClientListOptions) (*policy.Request, error) {
   144  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/firewallPolicies/{firewallPolicyName}/signatureOverrides"
   145  	if resourceGroupName == "" {
   146  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   147  	}
   148  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   149  	if firewallPolicyName == "" {
   150  		return nil, errors.New("parameter firewallPolicyName cannot be empty")
   151  	}
   152  	urlPath = strings.ReplaceAll(urlPath, "{firewallPolicyName}", url.PathEscape(firewallPolicyName))
   153  	if client.subscriptionID == "" {
   154  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   155  	}
   156  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   157  	req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   158  	if err != nil {
   159  		return nil, err
   160  	}
   161  	reqQP := req.Raw().URL.Query()
   162  	reqQP.Set("api-version", "2024-05-01")
   163  	req.Raw().URL.RawQuery = reqQP.Encode()
   164  	req.Raw().Header["Accept"] = []string{"application/json"}
   165  	return req, nil
   166  }
   167  
   168  // listHandleResponse handles the List response.
   169  func (client *FirewallPolicyIdpsSignaturesOverridesClient) listHandleResponse(resp *http.Response) (FirewallPolicyIdpsSignaturesOverridesClientListResponse, error) {
   170  	result := FirewallPolicyIdpsSignaturesOverridesClientListResponse{}
   171  	if err := runtime.UnmarshalAsJSON(resp, &result.SignaturesOverridesList); err != nil {
   172  		return FirewallPolicyIdpsSignaturesOverridesClientListResponse{}, err
   173  	}
   174  	return result, nil
   175  }
   176  
   177  // Patch - Will update the status of policy's signature overrides for IDPS
   178  // If the operation fails it returns an *azcore.ResponseError type.
   179  //
   180  // Generated from API version 2024-05-01
   181  //   - resourceGroupName - The name of the resource group.
   182  //   - firewallPolicyName - The name of the Firewall Policy.
   183  //   - parameters - Will contain all properties of the object to put
   184  //   - options - FirewallPolicyIdpsSignaturesOverridesClientPatchOptions contains the optional parameters for the FirewallPolicyIdpsSignaturesOverridesClient.Patch
   185  //     method.
   186  func (client *FirewallPolicyIdpsSignaturesOverridesClient) Patch(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters SignaturesOverrides, options *FirewallPolicyIdpsSignaturesOverridesClientPatchOptions) (FirewallPolicyIdpsSignaturesOverridesClientPatchResponse, error) {
   187  	var err error
   188  	const operationName = "FirewallPolicyIdpsSignaturesOverridesClient.Patch"
   189  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   190  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   191  	defer func() { endSpan(err) }()
   192  	req, err := client.patchCreateRequest(ctx, resourceGroupName, firewallPolicyName, parameters, options)
   193  	if err != nil {
   194  		return FirewallPolicyIdpsSignaturesOverridesClientPatchResponse{}, err
   195  	}
   196  	httpResp, err := client.internal.Pipeline().Do(req)
   197  	if err != nil {
   198  		return FirewallPolicyIdpsSignaturesOverridesClientPatchResponse{}, err
   199  	}
   200  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
   201  		err = runtime.NewResponseError(httpResp)
   202  		return FirewallPolicyIdpsSignaturesOverridesClientPatchResponse{}, err
   203  	}
   204  	resp, err := client.patchHandleResponse(httpResp)
   205  	return resp, err
   206  }
   207  
   208  // patchCreateRequest creates the Patch request.
   209  func (client *FirewallPolicyIdpsSignaturesOverridesClient) patchCreateRequest(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters SignaturesOverrides, options *FirewallPolicyIdpsSignaturesOverridesClientPatchOptions) (*policy.Request, error) {
   210  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/firewallPolicies/{firewallPolicyName}/signatureOverrides/default"
   211  	if resourceGroupName == "" {
   212  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   213  	}
   214  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   215  	if firewallPolicyName == "" {
   216  		return nil, errors.New("parameter firewallPolicyName cannot be empty")
   217  	}
   218  	urlPath = strings.ReplaceAll(urlPath, "{firewallPolicyName}", url.PathEscape(firewallPolicyName))
   219  	if client.subscriptionID == "" {
   220  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   221  	}
   222  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   223  	req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   224  	if err != nil {
   225  		return nil, err
   226  	}
   227  	reqQP := req.Raw().URL.Query()
   228  	reqQP.Set("api-version", "2024-05-01")
   229  	req.Raw().URL.RawQuery = reqQP.Encode()
   230  	req.Raw().Header["Accept"] = []string{"application/json"}
   231  	if err := runtime.MarshalAsJSON(req, parameters); err != nil {
   232  		return nil, err
   233  	}
   234  	return req, nil
   235  }
   236  
   237  // patchHandleResponse handles the Patch response.
   238  func (client *FirewallPolicyIdpsSignaturesOverridesClient) patchHandleResponse(resp *http.Response) (FirewallPolicyIdpsSignaturesOverridesClientPatchResponse, error) {
   239  	result := FirewallPolicyIdpsSignaturesOverridesClientPatchResponse{}
   240  	if err := runtime.UnmarshalAsJSON(resp, &result.SignaturesOverrides); err != nil {
   241  		return FirewallPolicyIdpsSignaturesOverridesClientPatchResponse{}, err
   242  	}
   243  	return result, nil
   244  }
   245  
   246  // Put - Will override/create a new signature overrides for the policy's IDPS
   247  // If the operation fails it returns an *azcore.ResponseError type.
   248  //
   249  // Generated from API version 2024-05-01
   250  //   - resourceGroupName - The name of the resource group.
   251  //   - firewallPolicyName - The name of the Firewall Policy.
   252  //   - parameters - Will contain all properties of the object to put
   253  //   - options - FirewallPolicyIdpsSignaturesOverridesClientPutOptions contains the optional parameters for the FirewallPolicyIdpsSignaturesOverridesClient.Put
   254  //     method.
   255  func (client *FirewallPolicyIdpsSignaturesOverridesClient) Put(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters SignaturesOverrides, options *FirewallPolicyIdpsSignaturesOverridesClientPutOptions) (FirewallPolicyIdpsSignaturesOverridesClientPutResponse, error) {
   256  	var err error
   257  	const operationName = "FirewallPolicyIdpsSignaturesOverridesClient.Put"
   258  	ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
   259  	ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
   260  	defer func() { endSpan(err) }()
   261  	req, err := client.putCreateRequest(ctx, resourceGroupName, firewallPolicyName, parameters, options)
   262  	if err != nil {
   263  		return FirewallPolicyIdpsSignaturesOverridesClientPutResponse{}, err
   264  	}
   265  	httpResp, err := client.internal.Pipeline().Do(req)
   266  	if err != nil {
   267  		return FirewallPolicyIdpsSignaturesOverridesClientPutResponse{}, err
   268  	}
   269  	if !runtime.HasStatusCode(httpResp, http.StatusOK) {
   270  		err = runtime.NewResponseError(httpResp)
   271  		return FirewallPolicyIdpsSignaturesOverridesClientPutResponse{}, err
   272  	}
   273  	resp, err := client.putHandleResponse(httpResp)
   274  	return resp, err
   275  }
   276  
   277  // putCreateRequest creates the Put request.
   278  func (client *FirewallPolicyIdpsSignaturesOverridesClient) putCreateRequest(ctx context.Context, resourceGroupName string, firewallPolicyName string, parameters SignaturesOverrides, options *FirewallPolicyIdpsSignaturesOverridesClientPutOptions) (*policy.Request, error) {
   279  	urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/firewallPolicies/{firewallPolicyName}/signatureOverrides/default"
   280  	if resourceGroupName == "" {
   281  		return nil, errors.New("parameter resourceGroupName cannot be empty")
   282  	}
   283  	urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
   284  	if firewallPolicyName == "" {
   285  		return nil, errors.New("parameter firewallPolicyName cannot be empty")
   286  	}
   287  	urlPath = strings.ReplaceAll(urlPath, "{firewallPolicyName}", url.PathEscape(firewallPolicyName))
   288  	if client.subscriptionID == "" {
   289  		return nil, errors.New("parameter client.subscriptionID cannot be empty")
   290  	}
   291  	urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
   292  	req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
   293  	if err != nil {
   294  		return nil, err
   295  	}
   296  	reqQP := req.Raw().URL.Query()
   297  	reqQP.Set("api-version", "2024-05-01")
   298  	req.Raw().URL.RawQuery = reqQP.Encode()
   299  	req.Raw().Header["Accept"] = []string{"application/json"}
   300  	if err := runtime.MarshalAsJSON(req, parameters); err != nil {
   301  		return nil, err
   302  	}
   303  	return req, nil
   304  }
   305  
   306  // putHandleResponse handles the Put response.
   307  func (client *FirewallPolicyIdpsSignaturesOverridesClient) putHandleResponse(resp *http.Response) (FirewallPolicyIdpsSignaturesOverridesClientPutResponse, error) {
   308  	result := FirewallPolicyIdpsSignaturesOverridesClientPutResponse{}
   309  	if err := runtime.UnmarshalAsJSON(resp, &result.SignaturesOverrides); err != nil {
   310  		return FirewallPolicyIdpsSignaturesOverridesClientPutResponse{}, err
   311  	}
   312  	return result, nil
   313  }