Skip to content

Commit

Permalink
Merge pull request #134 from akamai/release/v2.5.0
Browse files Browse the repository at this point in the history
Release/v2.5.0
  • Loading branch information
robertolopezlopez authored Jun 15, 2021
2 parents 518fdb7 + e8e6029 commit 093f835
Show file tree
Hide file tree
Showing 71 changed files with 5,414 additions and 4,560 deletions.
34 changes: 33 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
# EDGEGRID GOLANG RELEASE NOTES

## 2.5.0 (Jun 15, 2021)

#### BREAKING CHANGES:
* APPSEC
* The following have been removed, togther with their unit tests and test data:
* pkg/appsec/attack_group_action.go
* pkg/appsec/attack_group_condition_exception.go
* pkg/appsec/eval_rule_action.go
* pkg/appsec/eval_rule_condition_exception.go
* pkg/appsec/rule_action.go
* pkg/appsec/rule_condition_exception.go

#### BUG FIXES:
* DNSv2
* Fixed parsing SVCB, HTTPS rdata.

#### FEATURES/ENHANCEMENTS:
* [IMPORTANT] CPS - Added Certificate Provisioning API support
* Enrollments - create, read, update, delete enrollments
* Change status API - get change status, cancel change
* DV certificate API - get and acknowledge DV challenges
* Pre verification warnings - get and acknowledge pre verification warnings

* APPSEC
* The following have been added, together with their unit tests and test data:
* pkg/appsec/api_constraints_protection.go
* pkg/appsec/advanced_settings_pragma_header.go
* pkg/appsec/attack_group.go
* pkg/appsec/eval_rule.go
* pkg/appsec/rule.go
* pkg/appsec/ip_geo_protection.go

## 2.4.1 (Apr 19, 2021)

#### BUG FIXES
#### BUG FIXES:

* APPSEC
* Suppress 'null' text on output of empty/false values
Expand Down
170 changes: 170 additions & 0 deletions pkg/appsec/advanced_settings_pragma_header.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package appsec

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

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

// AdvancedSettingsPragma represents a collection of AdvancedSettingsPragma
//
// See: AdvancedSettingsPragma.GetAdvancedSettingsPragma()
// API Docs: // appsec v1
//
// https://developer.akamai.com/api/cloud_security/application_security/v1.html

type (
// AdvancedSettingsPragma contains operations available on AdvancedSettingsPragma resource
// See: // appsec v1
//
// https://developer.akamai.com/api/cloud_security/application_security/v1.html#getpragmaheaderconfiguration
AdvancedSettingsPragma interface {
GetAdvancedSettingsPragma(ctx context.Context, params GetAdvancedSettingsPragmaRequest) (*GetAdvancedSettingsPragmaResponse, error)
UpdateAdvancedSettingsPragma(ctx context.Context, params UpdateAdvancedSettingsPragmaRequest) (*UpdateAdvancedSettingsPragmaResponse, error)
}

GetAdvancedSettingsPragmaRequest struct {
ConfigID int `json:"-"`
Version int `json:"-"`
PolicyID string `json:"-"`
Group string `json:"group"`
}

GetAdvancedSettingsPragmaResponse struct {
Action string `json:"action,,omitempty"`
ConditionOperator string `json:"conditionOperator,omitempty"`
ExcludeCondition []ExcludeCondition `json:"excludeCondition,omitempty"`
}

ExcludeCondition struct {
Type string `json:"type"`
PositiveMatch bool `json:"positiveMatch"`
Header string `json:"header"`
Value []string `json:"value"`
Name string `json:"name"`
ValueCase bool `json:"valueCase"`
ValueWildcard bool `json:"valueWildcard"`
UseHeaders bool `json:"useHeaders"`
}

UpdateAdvancedSettingsPragmaRequest struct {
ConfigID int `json:"-"`
Version int `json:"-"`
PolicyID string `json:"-"`
JsonPayloadRaw json.RawMessage `json:"-"`
}
UpdateAdvancedSettingsPragmaResponse struct {
Action string `json:"action"`
ConditionOperator string `json:"conditionOperator"`
ExcludeCondition []ExcludeCondition `json:"excludeCondition"`
}
)

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

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

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

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

var rval GetAdvancedSettingsPragmaResponse
var uri string

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

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

req.Header.Set("Content-Type", "application/json")

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

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

return &rval, nil

}

// Update will update a AdvancedSettingsPragma.
//
// API Docs: // appsec v1
//
// https://developer.akamai.com/api/cloud_security/application_security/v1.html#putadvancedsettingsprefetch

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

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

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

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

var rval UpdateAdvancedSettingsPragmaResponse
resp, err := p.Exec(req, &rval, params.JsonPayloadRaw)
if err != nil {
return nil, fmt.Errorf("create AdvancedSettingsPragma request failed: %w", err)
}

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

return &rval, nil
}
Loading

0 comments on commit 093f835

Please sign in to comment.