github.com/akamai/AkamaiOPEN-edgegrid-golang/v8@v8.1.0/pkg/appsec/api_hostname_coverage.go (about) 1 package appsec 2 3 import ( 4 "context" 5 "fmt" 6 "net/http" 7 ) 8 9 type ( 10 // The ApiHostnameCoverage interface supports retrieving hostnames with their current protections, 11 // activation statuses, and other summary information. 12 ApiHostnameCoverage interface { 13 // GetApiHostnameCoverage gets the list of hostnames in the account with their current protections, activation statuses, and other summary information. 14 // 15 // See: https://techdocs.akamai.com/application-security/reference/get-hostname-coverage 16 GetApiHostnameCoverage(ctx context.Context, params GetApiHostnameCoverageRequest) (*GetApiHostnameCoverageResponse, error) 17 } 18 19 // GetApiHostnameCoverageRequest is used to call GetApiHostnameCoverage. 20 GetApiHostnameCoverageRequest struct { 21 ConfigID int `json:"-"` 22 Version int `json:"-"` 23 Hostname string `json:"-"` 24 } 25 26 // GetApiHostnameCoverageResponse is returned from a call to GetApiHostnameCoverage. 27 GetApiHostnameCoverageResponse struct { 28 HostnameCoverage []struct { 29 Configuration *ConfigurationHostnameCoverage `json:"configuration,omitempty"` 30 Status string `json:"status"` 31 HasMatchTarget bool `json:"hasMatchTarget"` 32 Hostname string `json:"hostname"` 33 PolicyNames []string `json:"policyNames"` 34 } `json:"hostnameCoverage"` 35 } 36 37 // ConfigurationHostnameCoverage describes a specific configuration version. 38 ConfigurationHostnameCoverage struct { 39 ID int `json:"id,omitempty"` 40 Name string `json:"name,omitempty"` 41 Version int `json:"version,omitempty"` 42 } 43 ) 44 45 func (p *appsec) GetApiHostnameCoverage(ctx context.Context, _ GetApiHostnameCoverageRequest) (*GetApiHostnameCoverageResponse, error) { 46 logger := p.Log(ctx) 47 logger.Debug("GetApiHostnameCoverage") 48 49 uri := "/appsec/v1/hostname-coverage" 50 req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil) 51 if err != nil { 52 return nil, fmt.Errorf("failed to create GetApiHostnameCoverage request: %w", err) 53 } 54 55 var result GetApiHostnameCoverageResponse 56 resp, err := p.Exec(req, &result) 57 if err != nil { 58 return nil, fmt.Errorf("get API hostname coverage request failed: %w", err) 59 } 60 if resp.StatusCode != http.StatusOK { 61 return nil, p.Error(resp) 62 } 63 64 return &result, nil 65 }