9 stable releases

2.1.0 Dec 3, 2023
2.0.4 Nov 28, 2023
2.0.2 Sep 14, 2023
1.0.3 Sep 8, 2023

#1121 in Web programming

Download history 14/week @ 2024-09-19 6/week @ 2024-09-26

105 downloads per month

MIT license

26KB
257 lines

outline-api

This package implements OutlineVPN Management API.

License Rust

Installation

To use this package, you'll need to have Rust and Cargo installed on your system. Once you have them, you can add this package to your application by running the following command:

cargo add outline-api

Usage

You can use this lib to build your own OutlineVPN management app like this:

main.rs

extern crate toml;

use std::{fs, io, time::Duration};
use toml::Value;

fn main() {
    let toml_str = fs::read_to_string("config.toml").expect("Failed to read config file");

    let toml_value: Value = toml::from_str(&toml_str).expect("Failed to parse config.toml");

    let server_section = toml_value
        .get("server")
        .expect("Missing [server] section")
        .as_table()
        .expect("[server] section should be a table");

    let cert_sha256 = server_section
        .get("cert_sha256")
        .and_then(Value::as_str)
        .expect("Missing or invalid cert_sha256");

    let api_url = server_section
        .get("api_url")
        .and_then(Value::as_str)
        .expect("Missing or invalid api_url");

    let request_timeout = server_section
        .get("request_timeout_in_sec")
        .and_then(|timeout| timeout.as_integer())
        .map(|timeout_secs| Duration::from_secs(timeout_secs as u64))
        .expect("Missing or invalid request_timeout");

    let vpn = outline_api::new(cert_sha256, api_url, Some(request_timeout));

    match vpn.get_server_info() {
        Ok(info) => println!("Server info: {}", info),
        Err(err) => eprintln!("Error getting server info: {}", err),
    }

    let raw_id = get_user_input("Provide user ID:");
    match raw_id.parse::<u16>() {
        Ok(id) => match vpn.delete_access_key_by_id(&id) {
            Ok(info) => println!("response: {:?}\n", info),
            Err(err) => {
                eprintln!("Error delete_access_key_by_id: {}", err)
            }
        },
        Err(_) => {
            eprintln!("Failed to parse the ID input as number (u16)");
        }
    }

    fn get_user_input(prompt: &str) -> String {
        println!("{}", prompt);
        let mut input = String::new();
        io::stdin()
            .read_line(&mut input)
            .expect("Failed to read line");
        input.trim().to_string()
    }
}

config.toml

[server]
cert_sha256 = "CERT_SHA256" # like E2DE8...2A75D
api_url = "https://<IP_ADDR>:<PORT>/<SECRET>"
request_timeout_in_sec = 5

Outline API

This is some important note about OutlineVPN API:

  • The official version of the API (see api.yml) is not quite right.
  • In fact, the /access-keys/<ID> endpoint is not available on the server.

Dependencies

~7–20MB
~288K SLoC