blob: 21f69e5c0b0da473ac834b7c70c06ff9a2209d4f (
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
40
41
42
43
44
45
|
# 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)"
}
}
def url [...parts] {
let suffix = $parts | str join '/'
$"($env.NETBIRD_MGMT_API_ENDPOINT)/api/($suffix)"
}
export def policy [] {}
export def "policy list" [] {
http get -H (headers) (url 'policies')
}
export def "policy get" [id] {
http get -H (headers) (url 'policies' $id)
}
export def "policy rm" [id] {
http delete -H (headers) (url 'policies' $id)
}
export def "policy new" [] {
$in
| clean-rules-for-write
| to json
| http post -H (headers) (url '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
}
}
|