github.com/akamai/AkamaiOPEN-edgegrid-golang/v8@v8.1.0/pkg/appsec/wap_bypass_network_lists.go (about)

     1  package appsec
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"net/http"
     7  
     8  	validation "github.com/go-ozzo/ozzo-validation/v4"
     9  )
    10  
    11  type (
    12  	// The WAPBypassNetworkLists interface supports listing or modifying which network lists are
    13  	// used in the bypass network lists settings.
    14  	WAPBypassNetworkLists interface {
    15  		// GetWAPBypassNetworkLists lists which network lists are used in the bypass network lists settings.
    16  		//
    17  		// See: https://techdocs.akamai.com/application-security/reference/get-bypass-network-lists
    18  		GetWAPBypassNetworkLists(ctx context.Context, params GetWAPBypassNetworkListsRequest) (*GetWAPBypassNetworkListsResponse, error)
    19  
    20  		// UpdateWAPBypassNetworkLists updates which network lists to use in the bypass network lists settings.
    21  		//
    22  		// See: https://techdocs.akamai.com/application-security/reference/put-bypass-network-lists
    23  		UpdateWAPBypassNetworkLists(ctx context.Context, params UpdateWAPBypassNetworkListsRequest) (*UpdateWAPBypassNetworkListsResponse, error)
    24  
    25  		// RemoveWAPBypassNetworkLists removes network lists in the bypass network lists settings.
    26  		//
    27  		// See: https://techdocs.akamai.com/application-security/reference/put-bypass-network-lists
    28  		RemoveWAPBypassNetworkLists(ctx context.Context, params RemoveWAPBypassNetworkListsRequest) (*RemoveWAPBypassNetworkListsResponse, error)
    29  	}
    30  
    31  	// GetWAPBypassNetworkListsRequest is used to list which network lists are used in the bypass network lists settings.
    32  	GetWAPBypassNetworkListsRequest struct {
    33  		ConfigID int    `json:"-"`
    34  		Version  int    `json:"-"`
    35  		PolicyID string `json:"policyId"`
    36  	}
    37  
    38  	// NetworkList is used to define a network list.
    39  	NetworkList struct {
    40  		Name string `json:"name"`
    41  		ID   string `json:"id"`
    42  	}
    43  
    44  	// GetWAPBypassNetworkListsResponse is returned from a call to GetWAPBypassNetworkLists.
    45  	GetWAPBypassNetworkListsResponse struct {
    46  		NetworkLists []NetworkList `json:"networkLists"`
    47  	}
    48  
    49  	// UpdateWAPBypassNetworkListsRequest is used to modify which network lists are used in the bypass network lists settings.
    50  	UpdateWAPBypassNetworkListsRequest struct {
    51  		ConfigID     int      `json:"-"`
    52  		Version      int      `json:"-"`
    53  		PolicyID     string   `json:"policyId"`
    54  		NetworkLists []string `json:"networkLists"`
    55  	}
    56  
    57  	// IPNetworkListsList is used to define a list of IP network lists.
    58  	IPNetworkListsList struct {
    59  		NetworkList []string `json:"networkList"`
    60  	}
    61  
    62  	// GeoControlsList is used to define a list of blocked IP network lists.
    63  	GeoControlsList struct {
    64  		BlockedIPNetworkLists IPNetworkListsList `json:"networkList"`
    65  	}
    66  
    67  	// IPControlsLists is used to define lists of allowed and blocked IP network lists.
    68  	IPControlsLists struct {
    69  		AllowedIPNetworkLists IPNetworkListsList `json:"allowedIPNetworkLists"`
    70  		BlockedIPNetworkLists IPNetworkListsList `json:"blockedIPNetworkLists"`
    71  	}
    72  
    73  	// UpdateWAPBypassNetworkListsResponse is returned from a call to UpdateWAPBypassNetworkLists.
    74  	UpdateWAPBypassNetworkListsResponse struct {
    75  		Block       string          `json:"block"`
    76  		GeoControls GeoControlsList `json:"geoControls"`
    77  		IPControls  IPControlsLists `json:"ipControls"`
    78  	}
    79  
    80  	// RemoveWAPBypassNetworkListsRequest is used to modify which network lists are used in the bypass network lists settings.
    81  	// Deprecated: this struct will be removed in a future release.
    82  	RemoveWAPBypassNetworkListsRequest struct {
    83  		ConfigID     int      `json:"-"`
    84  		Version      int      `json:"-"`
    85  		PolicyID     string   `json:"policyId"`
    86  		NetworkLists []string `json:"networkLists"`
    87  	}
    88  
    89  	// RemoveWAPBypassNetworkListsResponse is returned from a call to RemoveWAPBypassNetworkLists.
    90  	// Deprecated: this struct will be removed in a future release.
    91  	RemoveWAPBypassNetworkListsResponse struct {
    92  		NetworkLists []string `json:"networkLists"`
    93  	}
    94  )
    95  
    96  // Validate validates a GetWAPBypassNetworkListsRequest.
    97  func (v GetWAPBypassNetworkListsRequest) Validate() error {
    98  	return validation.Errors{
    99  		"ConfigID": validation.Validate(v.ConfigID, validation.Required),
   100  		"Version":  validation.Validate(v.Version, validation.Required),
   101  		"PolicyID": validation.Validate(v.PolicyID, validation.Required),
   102  	}.Filter()
   103  }
   104  
   105  // Validate validates an UpdateWAPBypassNetworkListsRequest.
   106  func (v UpdateWAPBypassNetworkListsRequest) Validate() error {
   107  	return validation.Errors{
   108  		"ConfigID": validation.Validate(v.ConfigID, validation.Required),
   109  		"Version":  validation.Validate(v.Version, validation.Required),
   110  		"PolicyID": validation.Validate(v.PolicyID, validation.Required),
   111  	}.Filter()
   112  }
   113  
   114  // Validate validates a RemoveWAPBypassNetworkListsRequest.
   115  // Deprecated: this method will be removed in a future release.
   116  func (v RemoveWAPBypassNetworkListsRequest) Validate() error {
   117  	return validation.Errors{
   118  		"ConfigID": validation.Validate(v.ConfigID, validation.Required),
   119  		"Version":  validation.Validate(v.Version, validation.Required),
   120  		"PolicyID": validation.Validate(v.PolicyID, validation.Required),
   121  	}.Filter()
   122  }
   123  
   124  func (p *appsec) GetWAPBypassNetworkLists(ctx context.Context, params GetWAPBypassNetworkListsRequest) (*GetWAPBypassNetworkListsResponse, error) {
   125  	logger := p.Log(ctx)
   126  	logger.Debugf("GetWAPBypassNetworkLists")
   127  
   128  	if err := params.Validate(); err != nil {
   129  		return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error())
   130  	}
   131  
   132  	uri := fmt.Sprintf(
   133  		"/appsec/v1/configs/%d/versions/%d/security-policies/%s/bypass-network-lists",
   134  		params.ConfigID,
   135  		params.Version,
   136  		params.PolicyID,
   137  	)
   138  
   139  	req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
   140  	if err != nil {
   141  		return nil, fmt.Errorf("failed to create GetWAPBypassNetworkLists request: %w", err)
   142  	}
   143  
   144  	var result GetWAPBypassNetworkListsResponse
   145  	resp, err := p.Exec(req, &result)
   146  	if err != nil {
   147  		return nil, fmt.Errorf("get WAP bypass network lists request failed: %w", err)
   148  	}
   149  	if resp.StatusCode != http.StatusOK {
   150  		return nil, p.Error(resp)
   151  	}
   152  
   153  	return &result, nil
   154  }
   155  
   156  func (p *appsec) UpdateWAPBypassNetworkLists(ctx context.Context, params UpdateWAPBypassNetworkListsRequest) (*UpdateWAPBypassNetworkListsResponse, error) {
   157  	logger := p.Log(ctx)
   158  	logger.Debugf("UpdateWAPBypassNetworkLists")
   159  
   160  	if err := params.Validate(); err != nil {
   161  		return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error())
   162  	}
   163  
   164  	uri := fmt.Sprintf(
   165  		"/appsec/v1/configs/%d/versions/%d/security-policies/%s/bypass-network-lists",
   166  		params.ConfigID,
   167  		params.Version,
   168  		params.PolicyID,
   169  	)
   170  
   171  	req, err := http.NewRequestWithContext(ctx, http.MethodPut, uri, nil)
   172  	if err != nil {
   173  		return nil, fmt.Errorf("failed to create UpdateWAPBypassNetworkLists request: %w", err)
   174  	}
   175  
   176  	var result UpdateWAPBypassNetworkListsResponse
   177  	resp, err := p.Exec(req, &result, params)
   178  	if err != nil {
   179  		return nil, fmt.Errorf("update WAP bypass network lists request failed: %w", err)
   180  	}
   181  	if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
   182  		return nil, p.Error(resp)
   183  	}
   184  
   185  	return &result, nil
   186  }
   187  
   188  // Deprecated: this method will be removed in a future release.
   189  func (p *appsec) RemoveWAPBypassNetworkLists(ctx context.Context, params RemoveWAPBypassNetworkListsRequest) (*RemoveWAPBypassNetworkListsResponse, error) {
   190  	logger := p.Log(ctx)
   191  	logger.Debugf("RemoveWAPBypassNetworkLists")
   192  
   193  	if err := params.Validate(); err != nil {
   194  		return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error())
   195  	}
   196  
   197  	uri := fmt.Sprintf(
   198  		"/appsec/v1/configs/%d/versions/%d/security-policies/%s/bypass-network-lists",
   199  		params.ConfigID,
   200  		params.Version,
   201  		params.PolicyID,
   202  	)
   203  
   204  	req, err := http.NewRequestWithContext(ctx, http.MethodPut, uri, nil)
   205  	if err != nil {
   206  		return nil, fmt.Errorf("failed to create RemoveWAPBypassNetworkLists request: %w", err)
   207  	}
   208  
   209  	var result RemoveWAPBypassNetworkListsResponse
   210  	resp, err := p.Exec(req, &result, params)
   211  	if err != nil {
   212  		return nil, fmt.Errorf("remove WAP bypass network lists request failed: %w", err)
   213  	}
   214  	if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
   215  		return nil, p.Error(resp)
   216  	}
   217  
   218  	return &result, nil
   219  }