/
api_hostname_coverage_match_targets.go
106 lines (92 loc) · 4.63 KB
/
api_hostname_coverage_match_targets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package appsec
import (
"context"
"fmt"
"net/http"
validation "github.com/go-ozzo/ozzo-validation/v4"
)
type (
// The ApiHostnameCoverageMatchTargets interface supports retrieving the API and website
// match targets that protect a hostname.
ApiHostnameCoverageMatchTargets interface {
// GetApiHostnameCoverageMatchTargets lists the API and website match targets that protect a hostname.
//
// See: https://techdocs.akamai.com/application-security/reference/get-coverage-match-targets
GetApiHostnameCoverageMatchTargets(ctx context.Context, params GetApiHostnameCoverageMatchTargetsRequest) (*GetApiHostnameCoverageMatchTargetsResponse, error)
}
// GetApiHostnameCoverageMatchTargetsRequest is used to retrieve the API and website match targets that protect a hostname.
GetApiHostnameCoverageMatchTargetsRequest struct {
ConfigID int `json:"-"`
Version int `json:"-"`
Hostname string `json:"-"`
}
// GetApiHostnameCoverageMatchTargetsResponse is returned from a call to GetApiHostnameCoverageMatchTargets.
GetApiHostnameCoverageMatchTargetsResponse struct {
MatchTargets struct {
WebsiteTargets []struct {
Type string `json:"type"`
BypassNetworkLists *HostnameCoverageMatchTargetBypassNetworkLists `json:"bypassNetworkLists,omitempty"`
ConfigID int `json:"configId"`
ConfigVersion int `json:"configVersion"`
DefaultFile string `json:"defaultFile"`
EffectiveSecurityControls *HostnameCoverageMatchTargetEffectiveSecurityControls `json:"effectiveSecurityControls,omitempty"`
FilePaths []string `json:"filePaths"`
Hostnames []string `json:"hostnames"`
IsNegativeFileExtensionMatch bool `json:"isNegativeFileExtensionMatch"`
IsNegativePathMatch bool `json:"isNegativePathMatch"`
SecurityPolicy struct {
PolicyID string `json:"policyId"`
} `json:"securityPolicy"`
Sequence int `json:"sequence"`
TargetID int `json:"targetId"`
} `json:"websiteTargets"`
APITargets []interface{} `json:"apiTargets"`
} `json:"matchTargets"`
}
// HostnameCoverageMatchTargetBypassNetworkLists describes a network list included in the list of bypass network lists.
HostnameCoverageMatchTargetBypassNetworkLists []struct {
ID string `json:"id"`
Name string `json:"name"`
}
// HostnameCoverageMatchTargetEffectiveSecurityControls describes the effective security controls for a website target.
HostnameCoverageMatchTargetEffectiveSecurityControls struct {
ApplyApplicationLayerControls bool `json:"applyApplicationLayerControls"`
ApplyBotmanControls bool `json:"applyBotmanControls"`
ApplyNetworkLayerControls bool `json:"applyNetworkLayerControls"`
ApplyRateControls bool `json:"applyRateControls"`
ApplyReputationControls bool `json:"applyReputationControls"`
ApplySlowPostControls bool `json:"applySlowPostControls"`
}
)
// Validate validates a GetApiHostnameCoverageMatchTargetsRequest.
func (v GetApiHostnameCoverageMatchTargetsRequest) Validate() error {
return validation.Errors{
"ConfigID": validation.Validate(v.ConfigID, validation.Required),
"Version": validation.Validate(v.Version, validation.Required),
}.Filter()
}
func (p *appsec) GetApiHostnameCoverageMatchTargets(ctx context.Context, params GetApiHostnameCoverageMatchTargetsRequest) (*GetApiHostnameCoverageMatchTargetsResponse, error) {
logger := p.Log(ctx)
logger.Debug("GetApiHostnameCoverageMatchTargets")
if err := params.Validate(); err != nil {
return nil, fmt.Errorf("%w: %s", ErrStructValidation, err.Error())
}
uri := fmt.Sprintf(
"/appsec/v1/configs/%d/versions/%d/hostname-coverage/match-targets?hostname=%s",
params.ConfigID,
params.Version,
params.Hostname)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, fmt.Errorf("failed to create GetApiHostnameCoverageMatchTargets request: %w", err)
}
var result GetApiHostnameCoverageMatchTargetsResponse
resp, err := p.Exec(req, &result)
if err != nil {
return nil, fmt.Errorf("get API hostname coverage match targets request failed: %w", err)
}
if resp.StatusCode != http.StatusOK {
return nil, p.Error(resp)
}
return &result, nil
}