Repository navigation
Expand file tree
/
Copy pathflowsspec.go
More file actions
74 lines (55 loc) · 1.67 KB
/
Copy pathflowsspec.go
File metadata and controls
74 lines (55 loc) · 1.67 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
package fastnetmon
import (
"fmt"
"github.com/levigross/grequests"
)
// Adds Flow Spec announce
func (client *FastNetMonClient) AddFlowSpecRule(flow_spec_rule FlowSpecRule) (bool, error) {
request_options := client.Ro
request_options.JSON = flow_spec_rule
resp, err := grequests.Put(client.Prefix+"/flowspec", grequests.FromRequestOptions(client.Ro))
if err != nil {
return false, fmt.Errorf("Cannot connect to API: %w", err)
}
if !resp.Ok {
return false, apiStatusError(resp)
}
response := ErrorJson{}
err = decodeResponseJSON(resp, &response)
if err != nil {
return false, err
}
return response.Success, nil
}
// Returns all active flow spec announces
func (client *FastNetMonClient) GetFlowSpecRules() ([]ResponseFlowSpecAnnounce, error) {
resp, err := grequests.Get(client.Prefix+"/flowspec", grequests.FromRequestOptions(client.Ro))
if err != nil {
return nil, fmt.Errorf("Cannot connect to API: %w", err)
}
if !resp.Ok {
return nil, apiStatusError(resp)
}
flow_spec_response := ResponseFlowSpecJson{}
err = decodeResponseJSON(resp, &flow_spec_response)
if err != nil {
return nil, err
}
return flow_spec_response.Values, nil
}
// Removes Flow Spec entry using UUID
func (client *FastNetMonClient) RemoveFlowSpecRule(mitigation_uuid string) (bool, error) {
resp, err := grequests.Delete(client.Prefix+"/flowspec/"+mitigation_uuid, grequests.FromRequestOptions(client.Ro))
if err != nil {
return false, fmt.Errorf("Cannot connect to API: %w", err)
}
if !resp.Ok {
return false, apiStatusError(resp)
}
response := ErrorJson{}
err = decodeResponseJSON(resp, &response)
if err != nil {
return false, err
}
return response.Success, nil
}