diff options
| author | Supremist <sergkarv@gmail.com> | 2026-05-16 15:58:45 +0300 |
|---|---|---|
| committer | Supremist <sergkarv@gmail.com> | 2026-05-16 15:58:45 +0300 |
| commit | b5e3cf93583da8f2cb7e1a4d88c490ed6bd1351e (patch) | |
| tree | 077e1f60c967f8adfdab47cf60904d85cc9defef /api/netbird-api.nu | |
| parent | 9ab97fc7effa3eb245af15657b62b85173bec15e (diff) | |
| download | netbird-b5e3cf93583da8f2cb7e1a4d88c490ed6bd1351e.tar.xz netbird-b5e3cf93583da8f2cb7e1a4d88c490ed6bd1351e.zip | |
Add netbird api nushell binding
Diffstat (limited to 'api/netbird-api.nu')
| -rw-r--r-- | api/netbird-api.nu | 39 |
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 |
