blob: c9f12ea14b90bee9b93eebcb055be9315f423beb (
plain)
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
|
# uses
# $env.NETBIRD_MGMT_API_ENDPOINT
# $env.NETBIRD_AUTH_TOKEN
def headers [] {
{
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": $"Token ($env.NETBIRD_AUTH_TOKEN)"
}
}
export def policy [] {}
export def "policy list" [] {
http get --headers (headers) $"($env.NETBIRD_MGMT_API_ENDPOINT)/api/policies"
}
export def "policy get" [id] {
http get --headers (headers) $"($env.NETBIRD_MGMT_API_ENDPOINT)/api/policies/($id)"
}
export def "policy rm" [id] {
http delete --headers (headers) $"($env.NETBIRD_MGMT_API_ENDPOINT)/api/policies/($id)"
}
export def "policy new" [] {
$in
| clean-rules-for-write
| http post --headers (headers) -t 'application/json' $"($env.NETBIRD_MGMT_API_ENDPOINT)/api/policies"
}
export def clean-rules-for-write [] {
let id_or_self = {|| $in | each {|x| if 'id' in $x { $x.id } else { $x } }}
$in | update rules {||
$in
| update sources $id_or_self
| update destinations $id_or_self
}
}
|