aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/netbird-api.nu39
1 files changed, 39 insertions, 0 deletions
diff --git a/api/netbird-api.nu b/api/netbird-api.nu
new file mode 100644
index 0000000..c9f12ea
--- /dev/null
+++ b/api/netbird-api.nu
@@ -0,0 +1,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
+ }
+} \ No newline at end of file