Add nu scripts to access mullvad api

This commit is contained in:
2024-02-28 14:09:43 +01:00
parent 9c40ab1ef4
commit aa2dc6ea15
2 changed files with 26 additions and 0 deletions

25
tree/.local/nu/mullvad.nu Normal file
View File

@ -0,0 +1,25 @@
# Get a Mullvad api access token from an account number
def m-token [
account: string # Mullvad account number
] {
(http post https://api.mullvad.net/auth/v1/token
-t application/json {account_number: $account}
).access_token
}
# Add a device to a mullvad account
def m-add-device [
account: string # Mullvad account number
] {
let token = (m-token $account)
let bearer = ("Bearer " + $token)
(http post https://api.mullvad.net/accounts/v1/devices
-t application/json
-H [Authorization $bearer]
{
pubkey: (wg genkey | wg pubkey),
hijack_dns: false,
kind: "App",
})
}