From c1904389a5cd69663f2641941f5d2e287db4bc3f Mon Sep 17 00:00:00 2001 From: Supremist Date: Sat, 16 May 2026 17:03:13 +0300 Subject: Clean up api usage code --- api/netbird-api.nu | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/api/netbird-api.nu b/api/netbird-api.nu index c9f12ea..21f69e5 100644 --- a/api/netbird-api.nu +++ b/api/netbird-api.nu @@ -9,24 +9,30 @@ def headers [] { "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 --headers (headers) $"($env.NETBIRD_MGMT_API_ENDPOINT)/api/policies" + http get -H (headers) (url 'policies') } export def "policy get" [id] { - http get --headers (headers) $"($env.NETBIRD_MGMT_API_ENDPOINT)/api/policies/($id)" + http get -H (headers) (url 'policies' $id) } export def "policy rm" [id] { - http delete --headers (headers) $"($env.NETBIRD_MGMT_API_ENDPOINT)/api/policies/($id)" + http delete -H (headers) (url '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" + | to json + | http post -H (headers) (url 'policies') } export def clean-rules-for-write [] { -- cgit v1.2.3