aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSupremist <sergkarv@gmail.com>2026-05-16 15:58:45 +0300
committerSupremist <sergkarv@gmail.com>2026-05-16 15:58:45 +0300
commitb5e3cf93583da8f2cb7e1a4d88c490ed6bd1351e (patch)
tree077e1f60c967f8adfdab47cf60904d85cc9defef
parent9ab97fc7effa3eb245af15657b62b85173bec15e (diff)
downloadnetbird-b5e3cf93583da8f2cb7e1a4d88c490ed6bd1351e.tar.xz
netbird-b5e3cf93583da8f2cb7e1a4d88c490ed6bd1351e.zip
Add netbird api nushell binding
-rw-r--r--.gitignore1
-rw-r--r--api/netbird-api.nu39
2 files changed, 40 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index bf9e8f3..b173980 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
backup/**
*.env
+env.json
config.yaml
traefik-dynamic.yaml
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