Skip to content

Commit

Permalink
Add user agent while fetching
Browse files Browse the repository at this point in the history
Add signature_version -> ciphersuite
Ensure Ciphersuite array is static, while bincode serialisation is only
supported when bincode option is enabled.
  • Loading branch information
thibmeu committed Oct 14, 2024
1 parent 7f89b2e commit cc326bb
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
command: fetch
- name: Build for target
working-directory: ./plexi_core
run: cargo build --verbose --no-default-features --target ${{ matrix.target }}
run: cargo build --verbose --no-default-features --features bincode --target ${{ matrix.target }}

bitrot:
name: Bitrot
Expand Down
17 changes: 9 additions & 8 deletions plexi_cli/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ use anyhow::{anyhow, Context, Result};
use colored::Colorize;
use log::log_enabled;
use plexi_core::{
auditor, client::PlexiClient, namespaces::Namespaces, Epoch, SignatureResponse,
SignatureVersion,
auditor, client::PlexiClient, namespaces::Namespaces, Ciphersuite, Epoch, SignatureResponse,
};
use reqwest::Url;
use tokio::time::interval;

const APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);

#[allow(dead_code)]
pub fn file_or_stdin(input: Option<PathBuf>) -> Result<Box<dyn io::Read>> {
let reader: Box<dyn io::Read> = match input {
Expand All @@ -39,7 +40,7 @@ pub fn file_or_stdout(output: Option<PathBuf>) -> Result<Box<dyn io::Write>> {
}

pub async fn ls(remote_url: &str, namespace: Option<&str>, long: bool) -> Result<String> {
let client = PlexiClient::new(Url::parse(remote_url)?, None)?;
let client = PlexiClient::new(Url::parse(remote_url)?, None, Some(APP_USER_AGENT))?;

let namespaces = if let Some(namespace) = namespace {
let mut namespaces = Namespaces::new();
Expand Down Expand Up @@ -94,11 +95,11 @@ pub async fn ls(remote_url: &str, namespace: Option<&str>, long: bool) -> Result
Ok(result.join("\n"))
}

fn format_ciphersuite(ciphersuite: &SignatureVersion) -> String {
fn format_ciphersuite(ciphersuite: &Ciphersuite) -> String {
match ciphersuite {
SignatureVersion::BincodeEd25519 => "ed25519(bincode)".to_string(),
SignatureVersion::ProtobufEd25519 => "ed25519(protobuf)".to_string(),
SignatureVersion::Unknown(u) => format!("unknown {u}"),
Ciphersuite::BincodeEd25519 => "ed25519(bincode)".to_string(),
Ciphersuite::ProtobufEd25519 => "ed25519(protobuf)".to_string(),
Ciphersuite::Unknown(u) => format!("unknown {u}"),
}
}

Expand Down Expand Up @@ -195,7 +196,7 @@ pub async fn audit(
verifying_key: Option<&str>,
epoch: Option<&Epoch>,
) -> Result<String> {
let client = PlexiClient::new(Url::parse(remote_url)?, None)?;
let client = PlexiClient::new(Url::parse(remote_url)?, None, Some(APP_USER_AGENT))?;
let epoch = match epoch {
Some(epoch) => epoch,
None => {
Expand Down
4 changes: 2 additions & 2 deletions plexi_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ build = "src/build.rs"
[features]
default = ["openapi", "bincode"]
auditor = ["akd", "akd/parallel_vrf", "akd/parallel_insert", "akd/experimental"]
client = ["auditor", "reqwest", "bincode"]
openapi = ["utoipa"]
bincode = ["dep:bincode"]
client = ["auditor", "bincode", "reqwest"]
openapi = ["utoipa"]

[dependencies]
akd = { workspace = true, features = ["whatsapp_v1", "public_auditing"], optional = true }
Expand Down
10 changes: 9 additions & 1 deletion plexi_core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ impl fmt::Debug for PlexiClient {
}

impl PlexiClient {
pub fn new(base_url: Url, mtls: Option<ClientMtls>) -> anyhow::Result<Self> {
pub fn new(
base_url: Url,
mtls: Option<ClientMtls>,
user_agent: Option<&str>,
) -> anyhow::Result<Self> {
let mut client_builder = Client::builder();

if let Ok(bundle) = std::env::var("SSL_CERT_FILE") {
Expand All @@ -46,6 +50,10 @@ impl PlexiClient {
client_builder = client_builder.identity(mtls.identity);
}

if let Some(user_agent) = user_agent {
client_builder = client_builder.user_agent(user_agent);
}

Ok(Self {
base_url,
client: client_builder
Expand Down
Loading

0 comments on commit cc326bb

Please sign in to comment.