Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 98 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions aw-client-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ edition = "2021"
authors = ["Johan Bjäreholt <johan@bjareho.lt>"]

[dependencies]
reqwest = { version = "0.11", features = ["json", "blocking"] }
reqwest = { version = "0.11", default-features = false, features = ["json", "blocking", "rustls-tls-native-roots"] }
gethostname = "0.4"
serde = { version = "1.0", features = ["derive"] }
phf = { version = "0.11", features = ["macros"] }
serde_json = "1.0"
chrono = { version = "0.4", features = ["serde"] }
aw-models = { path = "../aw-models" }
tokio = { version = "1.28.2", features = ["rt"] }
rand = "0.9"
log = "0.4"
libc = "0.2"
thiserror = "1.0"
thiserror = "1.0"
dirs = "6.0"
fs4 = { version = "0.13", features = ["sync"] }

Expand All @@ -25,3 +24,4 @@ aw-datastore = { path = "../aw-datastore" }
aw-server = { path = "../aw-server", default-features = false, features=[] }
rocket = "0.5.0-rc.1"
tokio-test = "*"
toml = "0.8"
11 changes: 10 additions & 1 deletion aw-client-rust/src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ macro_rules! proxy_method

impl AwClient {
pub fn new(host: &str, port: u16, name: &str) -> Result<AwClient, Box<dyn Error>> {
let async_client = AsyncAwClient::new(host, port, name)?;
Self::new_with_api_key(host, port, name, None)
}

pub fn new_with_api_key(
host: &str,
port: u16,
name: &str,
api_key: Option<String>,
) -> Result<AwClient, Box<dyn Error>> {
let async_client = AsyncAwClient::new_with_api_key(host, port, name, api_key)?;

Ok(AwClient {
baseurl: async_client.baseurl.clone(),
Expand Down
28 changes: 25 additions & 3 deletions aw-client-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod single_instance;
use std::{collections::HashMap, error::Error};

use chrono::{DateTime, Utc};
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION};
use serde_json::{json, Map};
use single_instance::SingleInstance;
use std::net::TcpStream;
Expand All @@ -39,13 +40,34 @@ fn get_hostname() -> String {
gethostname::gethostname().to_string_lossy().to_string()
}

fn build_client(api_key: Option<String>) -> Result<reqwest::Client, Box<dyn Error>> {
let mut headers = HeaderMap::new();
if let Some(api_key) = api_key {
let mut header_value = HeaderValue::from_str(&format!("Bearer {api_key}"))?;
header_value.set_sensitive(true);
headers.insert(AUTHORIZATION, header_value);
}

Ok(reqwest::Client::builder()
.timeout(std::time::Duration::from_secs(120))
.default_headers(headers)
.build()?)
}

impl AwClient {
pub fn new(host: &str, port: u16, name: &str) -> Result<AwClient, Box<dyn Error>> {
Self::new_with_api_key(host, port, name, None)
}

pub fn new_with_api_key(
host: &str,
port: u16,
name: &str,
api_key: Option<String>,
) -> Result<AwClient, Box<dyn Error>> {
let baseurl = reqwest::Url::parse(&format!("http://{}:{}", host, port))?;
let hostname = get_hostname();
let client = reqwest::Client::builder()
.timeout(std::time::Duration::from_secs(120))
.build()?;
let client = build_client(api_key)?;
//TODO: change localhost string to 127.0.0.1 for feature parity
let single_instance_name = format!("{}-at-{}-on-{}", name, host, port);
let single_instance = single_instance::SingleInstance::new(single_instance_name.as_str())?;
Expand Down
Loading
Loading