-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapi_discovery.go
More file actions
107 lines (95 loc) · 4.42 KB
/
Copy pathapi_discovery.go
File metadata and controls
107 lines (95 loc) · 4.42 KB
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
107
package wallarm
import (
"encoding/json"
"fmt"
)
type (
// APIDiscovery contains operations available on the API Discovery
// configuration resource. The config is a singleton per client_id —
// no Create/Delete; only Read and Update.
APIDiscovery interface {
APIDiscoveryConfigRead(clientID int) (*APIDiscoveryConfig, error)
APIDiscoveryConfigUpdate(clientID int, cfg *APIDiscoveryConfig) error
}
// APIDiscoveryConfig mirrors the API Discovery config body returned by
// GET /v1/clients/{client_id}/apid/config and accepted by POST on the
// same path.
APIDiscoveryConfig struct {
ClientID int `json:"clientid"`
Enabled bool `json:"enabled"`
Protocols APIDiscoveryProtocols `json:"protocols"`
ApplyExtendedFilter bool `json:"apply_extended_filter"`
TypeDetectionThreshold float64 `json:"type_detection_threshold"`
PIIDetectionThreshold float64 `json:"pii_detection_threshold"`
CallPointsStorageLimit int `json:"call_points_storage_limit"`
SensitiveSamples APIDiscoverySensitiveSamples `json:"sensitive_samples"`
DisabledApps []int `json:"disabled_apps"`
EndpointStability APIDiscoveryEndpointStability `json:"endpoint_stability"`
GroupSOAP bool `json:"group_soap"`
ServerVariability APIDiscoveryServerVariability `json:"server_variability"`
AllowedContentTypesPatterns []string `json:"allowed_content_types_patterns"`
ExtensionsWhitelist APIDiscoveryExtensionsWhitelist `json:"extensions_whitelist"`
}
APIDiscoveryProtocols struct {
REST bool `json:"rest"`
GraphQL bool `json:"graphql"`
SOAP bool `json:"soap"`
GRPC bool `json:"grpc"`
MCP bool `json:"mcp"`
}
APIDiscoverySensitiveSamples struct {
Enabled bool `json:"enabled"`
MinMasked int `json:"min_masked"`
MaxMasked int `json:"max_masked"`
MaskSymbols bool `json:"mask_symbols"`
}
APIDiscoveryEndpointStability struct {
MinCount int `json:"min_count"`
MinTime int `json:"min_time"`
}
APIDiscoveryServerVariability struct {
Enabled bool `json:"enabled"`
ByDateEnabled bool `json:"by_date_enabled"`
ByLocalCodeEnabled bool `json:"by_local_code_enabled"`
ByEmailEnabled bool `json:"by_email_enabled"`
ByAlphanumericIDEnabled bool `json:"by_alphanumeric_id_enabled"`
ByCustomPaths APIDiscoveryServerVariabilityByCustomPaths `json:"by_custom_paths"`
}
APIDiscoveryServerVariabilityByCustomPaths struct {
Enabled bool `json:"enabled"`
Paths []string `json:"paths"`
}
APIDiscoveryExtensionsWhitelist struct {
Enabled bool `json:"enabled"`
Extensions []string `json:"extensions"`
}
APIDiscoveryConfigResp struct {
Status int `json:"status"`
Body *APIDiscoveryConfig `json:"body"`
}
)
// APIDiscoveryConfigRead fetches the API Discovery configuration for the
// given client.
func (api *api) APIDiscoveryConfigRead(clientID int) (*APIDiscoveryConfig, error) {
uri := fmt.Sprintf("/v1/clients/%d/apid/config", clientID)
respBody, err := api.makeRequest("GET", uri, "api_discovery", nil, nil)
if err != nil {
return nil, fmt.Errorf("APIDiscoveryConfigRead: %w", err)
}
var resp APIDiscoveryConfigResp
if err := json.Unmarshal(respBody, &resp); err != nil {
return nil, fmt.Errorf("APIDiscoveryConfigRead: failed to parse response - %w", err)
}
return resp.Body, nil
}
// APIDiscoveryConfigUpdate writes the full API Discovery configuration.
// The endpoint is an upsert — the singleton record always exists, so this
// is the only way to mutate any field. The cfg.ClientID JSON tag (`clientid`)
// is sent in the body alongside the path parameter.
func (api *api) APIDiscoveryConfigUpdate(clientID int, cfg *APIDiscoveryConfig) error {
uri := fmt.Sprintf("/v1/clients/%d/apid/config", clientID)
if _, err := api.makeRequest("POST", uri, "api_discovery", cfg, nil); err != nil {
return fmt.Errorf("APIDiscoveryConfigUpdate: %w", err)
}
return nil
}