# 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",
        })
}
