Skip to content

Commit

Permalink
DXE-333 Feature/security v2 january new
Browse files Browse the repository at this point in the history
Merge in DEVEXP/akamaiopen-edgegrid-golang from feature/security-v2-january-new to v2
  • Loading branch information
robertolopezlopez committed Jan 17, 2022
1 parent 4f9fd24 commit fe0beb8
Show file tree
Hide file tree
Showing 8 changed files with 1,548 additions and 16 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# EDGEGRID GOLANG RELEASE NOTES

## 2.9.0 (Jan. 11, 2022)

#### FEATURES/ENHANCEMENTS:

* APPSEC
* Add support for Evasive Path Match feature
* Deprecate individual policy protection interface methods

* NETWORK LISTS
* Include ContractID and GroupID in GetNetworkListResponse

## 2.8.1 (Nov. 30, 2021)

#### FEATURES/ENHANCEMENTS:
Expand Down
190 changes: 190 additions & 0 deletions pkg/appsec/advanced_settings_evasive_path_match.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package appsec

import (
"context"
"fmt"
"net/http"

validation "github.com/go-ozzo/ozzo-validation/v4"
)

type (
// The AdvancedSettingsEvasivePathMatch supports retrieving or modifying the Evasive Path Match setting.
//
// https://developer.akamai.com/api/cloud_security/application_security/v1.html
AdvancedSettingsEvasivePathMatch interface {
// GetAdvancedSettingsEvasivePathMatch retrieves the Evasive Path Match setting
GetAdvancedSettingsEvasivePathMatch(ctx context.Context, params GetAdvancedSettingsEvasivePathMatchRequest) (*GetAdvancedSettingsEvasivePathMatchResponse, error)
// UpdateAdvancedSettingsEvasivePathMatch modifies the Evasive Path Match setting
UpdateAdvancedSettingsEvasivePathMatch(ctx context.Context, params UpdateAdvancedSettingsEvasivePathMatchRequest) (*UpdateAdvancedSettingsEvasivePathMatchResponse, error)
// RemoveAdvancedSettingsEvasivePathMatch removes the Evasive Path Match setting
RemoveAdvancedSettingsEvasivePathMatch(ctx context.Context, params RemoveAdvancedSettingsEvasivePathMatchRequest) (*RemoveAdvancedSettingsEvasivePathMatchResponse, error)
}

// GetAdvancedSettingsEvasivePathMatchRequest is used to retrieve the EvasivePathMatch setting
GetAdvancedSettingsEvasivePathMatchRequest struct {
ConfigID int `json:"-"`
Version int `json:"-"`
PolicyID string `json:"-"`
}

// GetAdvancedSettingsEvasivePathMatchResponse returns the EvasivePathMatch setting
GetAdvancedSettingsEvasivePathMatchResponse struct {
EnablePathMatch bool `json:"enablePathMatch"`
}

// UpdateAdvancedSettingsEvasivePathMatchRequest is used to update the EvasivePathMatch setting
UpdateAdvancedSettingsEvasivePathMatchRequest struct {
ConfigID int `json:"-"`
Version int `json:"-"`
PolicyID string `json:"-"`
EnablePathMatch bool `json:"enablePathMatch"`
}

// UpdateAdvancedSettingsEvasivePathMatchResponse returns the result of updating the EvasivePathMatch setting
UpdateAdvancedSettingsEvasivePathMatchResponse struct {
EnablePathMatch bool `json:"enablePathMatch"`
}

// RemoveAdvancedSettingsEvasivePathMatchRequest is used to clear the EvasivePathMatch setting
RemoveAdvancedSettingsEvasivePathMatchRequest struct {
ConfigID int `json:"-"`
Version int `json:"-"`
PolicyID string `json:"-"`
EnablePathMatch bool `json:"enablePathMatch"`
}

// RemoveAdvancedSettingsEvasivePathMatchResponse returns the result of clearing the EvasivePathMatch setting
RemoveAdvancedSettingsEvasivePathMatchResponse struct {
ConfigID int `json:"-"`
Version int `json:"-"`
PolicyID string `json:"-"`
EnablePathMatch bool `json:"enablePathMatch"`
}
)

// Validate validates GetAdvancedSettingssEvasivePathMatchRequest
func (v GetAdvancedSettingsEvasivePathMatchRequest) Validate() error {
return validation.Errors{
"ConfigID": validation.Validate(v.ConfigID, validation.Required),
"Version": validation.Validate(v.Version, validation.Required),
}.Filter()
}

// Validate validates UpdateAdvancedSettingsEvasivePathMatchRequest
func (v UpdateAdvancedSettingsEvasivePathMatchRequest) Validate() error {
return validation.Errors{
"ConfigID": validation.Validate(v.ConfigID, validation.Required),
"Version": validation.Validate(v.Version, validation.Required),
}.Filter()
}

// Validate validates UpdateAdvancedSettingsEvasivePathMatchRequest
func (v RemoveAdvancedSettingsEvasivePathMatchRequest) Validate() error {
return validation.Errors{
"ConfigID": validation.Validate(v.ConfigID, validation.Required),
"Version": validation.Validate(v.Version, validation.Required),
}.Filter()
}

func (p *appsec) GetAdvancedSettingsEvasivePathMatch(ctx context.Context, params GetAdvancedSettingsEvasivePathMatchRequest) (*GetAdvancedSettingsEvasivePathMatchResponse, error) {
if err := params.Validate(); err != nil {
return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error())
}

logger := p.Log(ctx)
logger.Debug("GetAdvancedSettingsLoggings")

var rval GetAdvancedSettingsEvasivePathMatchResponse
var uri string

if params.PolicyID != "" {
uri = fmt.Sprintf(
"/appsec/v1/configs/%d/versions/%d/security-policies/%s/advanced-settings/evasive-path-match",
params.ConfigID,
params.Version,
params.PolicyID)
} else {
uri = fmt.Sprintf(
"/appsec/v1/configs/%d/versions/%d/advanced-settings/evasive-path-match",
params.ConfigID,
params.Version)
}

req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, fmt.Errorf("failed to create getadvancedsettingsloggings request: %w", err)
}

resp, err := p.Exec(req, &rval)
if err != nil {
return nil, fmt.Errorf("getadvancedsettingsloggings request failed: %w", err)
}

if resp.StatusCode != http.StatusOK {
return nil, p.Error(resp)
}

return &rval, nil
}

func (p *appsec) UpdateAdvancedSettingsEvasivePathMatch(ctx context.Context, params UpdateAdvancedSettingsEvasivePathMatchRequest) (*UpdateAdvancedSettingsEvasivePathMatchResponse, error) {
if err := params.Validate(); err != nil {
return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error())
}

logger := p.Log(ctx)
logger.Debug("UpdateAdvancedSettingsLogging")

var putURL string
if params.PolicyID != "" {
putURL = fmt.Sprintf(
"/appsec/v1/configs/%d/versions/%d/security-policies/%s/advanced-settings/evasive-path-match",
params.ConfigID,
params.Version,
params.PolicyID)
} else {
putURL = fmt.Sprintf(
"/appsec/v1/configs/%d/versions/%d/advanced-settings/evasive-path-match",
params.ConfigID,
params.Version)
}

req, err := http.NewRequestWithContext(ctx, http.MethodPut, putURL, nil)
if err != nil {
return nil, fmt.Errorf("failed to create create AdvancedSettingsLoggingrequest: %w", err)
}

req.Header.Set("Content-Type", "application/json")
var rval UpdateAdvancedSettingsEvasivePathMatchResponse
resp, err := p.Exec(req, &rval, params)
if err != nil {
return nil, fmt.Errorf("create AdvancedSettingsLogging request failed: %w", err)
}

if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
return nil, p.Error(resp)
}

return &rval, nil
}

func (p *appsec) RemoveAdvancedSettingsEvasivePathMatch(ctx context.Context, params RemoveAdvancedSettingsEvasivePathMatchRequest) (*RemoveAdvancedSettingsEvasivePathMatchResponse, error) {
request := UpdateAdvancedSettingsEvasivePathMatchRequest{
ConfigID: params.ConfigID,
Version: params.Version,
PolicyID: params.PolicyID,
EnablePathMatch: false,
}
_, err := p.UpdateAdvancedSettingsEvasivePathMatch(ctx, request)
if err != nil {
return nil, fmt.Errorf("UpdateAdvancedSettingsEvasivePathMatch request failed: %w", err)
}
response := RemoveAdvancedSettingsEvasivePathMatchResponse{
ConfigID: params.ConfigID,
Version: params.Version,
PolicyID: params.PolicyID,
EnablePathMatch: false,
}
return &response, nil
}
Loading

0 comments on commit fe0beb8

Please sign in to comment.