-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AirVPN Provider with optional auth file #121
Conversation
Thanks! Overall it looks great, the only thing I'd change is to use serde instead of rustc_serialize even though it's "overkill" for just JSON because we are already using it anyway (for TOML, etc.). |
I could replace it with diff for diff --git a/Cargo.toml b/Cargo.toml
index 95b264b..b4b3e19 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -45,7 +45,7 @@ webbrowser = "0.5"
basic_tcp_proxy = "0.3"
signal-hook = "0.3"
config = "0.11"
-rustc-serialize = "0.3"
+serde_json = "1.0"
bs58 = "0.4"
[package.metadata.rpm]
diff --git a/src/providers/airvpn/openvpn.rs b/src/providers/airvpn/openvpn.rs
index 1b691f9..a9a96f2 100644
--- a/src/providers/airvpn/openvpn.rs
+++ b/src/providers/airvpn/openvpn.rs
@@ -2,6 +2,8 @@ use super::AirVPN;
use super::{ConfigurationChoice, OpenVpnProvider};
use crate::util::delete_all_files_in_dir;
use log::debug;
+use serde_json::Value;
+use std::collections::HashMap;
use std::env;
use std::fmt::Display;
use std::fs::create_dir_all;
@@ -13,9 +15,6 @@ use strum::IntoEnumIterator;
use strum_macros::EnumIter;
use zip::ZipArchive;
-extern crate rustc_serialize;
-use rustc_serialize::json::Json;
-
impl OpenVpnProvider for AirVPN {
fn provider_dns(&self) -> Option<Vec<IpAddr>> {
None
@@ -41,13 +40,14 @@ impl OpenVpnProvider for AirVPN {
.send()?
.text()?;
- let status_response_json = Json::from_str(&status_response).unwrap();
- let status_response_obj = status_response_json.as_object().unwrap();
- let all_servers_array = status_response_obj
+ let deserialized_json: HashMap<String, Value> =
+ serde_json::from_str(&status_response).unwrap();
+ let all_servers_array = deserialized_json
.get("servers")
.unwrap()
.as_array()
.unwrap();
+
let mut request_server_names = "".to_string();
for item in all_servers_array {
let public_name = item
@@ -55,13 +55,13 @@ impl OpenVpnProvider for AirVPN {
.unwrap()
.get("public_name")
.unwrap()
- .as_string()
- .unwrap();
+ .to_string()
+ .replace("\"", "");
if !request_server_names.is_empty() {
// separate server names with '%2C'
request_server_names.push_str("%2C");
}
- request_server_names.push_str(public_name);
+ request_server_names.push_str(&public_name);
}
let generator_url = config_choice
|
Exactly, I think it's better to keep it all in serde, even though it means adding Could you please commit it? and I'll let the Github actions run. |
Thanks! |
Code for the provider AirVPN. I have adapted the OpenVPN API accordingly so that an auth file is now optional. Unfortunately I have little experience with rust and the implementation will probably not be optimal. Therefore feel free to adapt it to your needs.
I don't have check if the changes break OpenVPN with auth file!