From b5e3cf93583da8f2cb7e1a4d88c490ed6bd1351e Mon Sep 17 00:00:00 2001 From: Supremist Date: Sat, 16 May 2026 15:58:45 +0300 Subject: Add netbird api nushell binding --- api/netbird-api.nu | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 api/netbird-api.nu (limited to 'api') 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 -- cgit v1.2.3