-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathapi_hostname_coverage.go
69 lines (58 loc) · 2.37 KB
/
api_hostname_coverage.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
package appsec
import (
"context"
"fmt"
"net/http"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/v10/pkg/session"
)
type (
// The ApiHostnameCoverage interface supports retrieving hostnames with their current protections,
// activation statuses, and other summary information.
ApiHostnameCoverage interface {
// GetApiHostnameCoverage gets the list of hostnames in the account with their current protections, activation statuses, and other summary information.
//
// See: https://techdocs.akamai.com/application-security/reference/get-hostname-coverage
GetApiHostnameCoverage(ctx context.Context, params GetApiHostnameCoverageRequest) (*GetApiHostnameCoverageResponse, error)
}
// GetApiHostnameCoverageRequest is used to call GetApiHostnameCoverage.
GetApiHostnameCoverageRequest struct {
ConfigID int `json:"-"`
Version int `json:"-"`
Hostname string `json:"-"`
}
// GetApiHostnameCoverageResponse is returned from a call to GetApiHostnameCoverage.
GetApiHostnameCoverageResponse struct {
HostnameCoverage []struct {
Configuration *ConfigurationHostnameCoverage `json:"configuration,omitempty"`
Status string `json:"status"`
HasMatchTarget bool `json:"hasMatchTarget"`
Hostname string `json:"hostname"`
PolicyNames []string `json:"policyNames"`
} `json:"hostnameCoverage"`
}
// ConfigurationHostnameCoverage describes a specific configuration version.
ConfigurationHostnameCoverage struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Version int `json:"version,omitempty"`
}
)
func (p *appsec) GetApiHostnameCoverage(ctx context.Context, _ GetApiHostnameCoverageRequest) (*GetApiHostnameCoverageResponse, error) {
logger := p.Log(ctx)
logger.Debug("GetApiHostnameCoverage")
uri := "/appsec/v1/hostname-coverage"
req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, fmt.Errorf("failed to create GetApiHostnameCoverage request: %w", err)
}
var result GetApiHostnameCoverageResponse
resp, err := p.Exec(req, &result)
if err != nil {
return nil, fmt.Errorf("get API hostname coverage request failed: %w", err)
}
defer session.CloseResponseBody(resp)
if resp.StatusCode != http.StatusOK {
return nil, p.Error(resp)
}
return &result, nil
}