Add nu scripts to access mullvad api
This commit is contained in:
@ -826,6 +826,7 @@ alias xo = xdg-open
|
|||||||
|
|
||||||
# random scripts
|
# random scripts
|
||||||
source ~/.local/nu/readelf.nu
|
source ~/.local/nu/readelf.nu
|
||||||
|
source ~/.local/nu/mullvad.nu
|
||||||
|
|
||||||
# init zoxide
|
# init zoxide
|
||||||
source ~/.cache/zoxide.nu
|
source ~/.cache/zoxide.nu
|
||||||
|
|||||||
25
tree/.local/nu/mullvad.nu
Normal file
25
tree/.local/nu/mullvad.nu
Normal 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",
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user