From f3f013fc9da5e8bea637dce82f1f132fdc5fc1bb Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Fri, 14 Jun 2024 11:12:11 +0200 Subject: [PATCH] Remove sq network wkd url and direct-url. - These leak implementation details and support the idea that WKD is just a http request to some URL, which is not true, and will be less true in the future. I don't think this is an interface that we can support going forward. --- src/cli/network/wkd.rs | 26 ---------------- src/commands/network.rs | 18 ----------- src/main.rs | 2 +- src/output.rs | 68 ----------------------------------------- 4 files changed, 1 insertion(+), 113 deletions(-) diff --git a/src/cli/network/wkd.rs b/src/cli/network/wkd.rs index 20e547aa..d279dbc3 100644 --- a/src/cli/network/wkd.rs +++ b/src/cli/network/wkd.rs @@ -33,32 +33,6 @@ pub struct Command { pub enum Subcommands { Fetch(FetchCommand), Publish(PublishCommand), - DirectUrl(DirectUrlCommand), - Url(UrlCommand), -} - -#[derive(Debug, Args)] -#[clap( - about = "Print the advanced Web Key Directory URL of an email address", -)] -pub struct UrlCommand { - #[clap( - value_name = "ADDRESS", - help = "Query for ADDRESS", - )] - pub email_address: String, -} - -#[derive(Debug, Args)] -#[clap( - about = "Print the direct Web Key Directory URL of an email address", -)] -pub struct DirectUrlCommand { - #[clap( - value_name = "ADDRESS", - help = "Query for ADDRESS", - )] - pub email_address: String, } #[derive(Debug, Args)] diff --git a/src/commands/network.rs b/src/commands/network.rs index e70ed9c9..4e608f4e 100644 --- a/src/commands/network.rs +++ b/src/commands/network.rs @@ -52,10 +52,8 @@ use crate::{ pluralize::Pluralize, }, Sq, - Model, merge_keyring, serialize_keyring, - output::WkdUrlVariant, print_error_chain, utils::cert_exportable, }; @@ -983,22 +981,6 @@ pub fn dispatch_wkd(mut sq: Sq, c: cli::network::wkd::Command) use crate::cli::network::wkd::Subcommands::*; match c.subcommand { - Url(c) => { - let wkd_url = wkd::Url::from(&c.email_address)?; - let advanced = wkd_url.to_url(None)?.to_string(); - let direct = wkd_url.to_url(wkd::Variant::Direct)?.to_string(); - let output = Model::wkd_url(sq.output_version, - WkdUrlVariant::Advanced, advanced, direct)?; - output.write(sq.output_format, &mut std::io::stdout())?; - }, - DirectUrl(c) => { - let wkd_url = wkd::Url::from(&c.email_address)?; - let advanced = wkd_url.to_url(None)?.to_string(); - let direct = wkd_url.to_url(wkd::Variant::Direct)?.to_string(); - let output = Model::wkd_url(sq.output_version, - WkdUrlVariant::Direct, advanced, direct)?; - output.write(sq.output_format, &mut std::io::stdout())?; - }, Fetch(c) => rt.block_on(async { let mut pb = Response::progress_bar(&sq); let http_client = http_client()?; diff --git a/src/main.rs b/src/main.rs index 839e7a5d..e9bc1d9e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,7 +50,7 @@ use cli::output::{OutputFormat, OutputVersion}; mod commands; pub mod output; -pub use output::{wkd::WkdUrlVariant, Model}; +pub use output::Model; /// Converts sequoia_openpgp types for rendering. pub trait Convert { diff --git a/src/output.rs b/src/output.rs index 0f842e89..bba3077d 100644 --- a/src/output.rs +++ b/src/output.rs @@ -13,7 +13,6 @@ pub mod sanitize; pub mod wrapping; pub use keyring::ListItem as KeyringListItem; -pub use wkd::WkdUrlVariant; use crate::cli::output::{OutputFormat, OutputVersion}; @@ -30,7 +29,6 @@ pub const OUTPUT_VERSIONS: &[OutputVersion] = &[OutputVersion::new(0, 0, 0)]; /// Each variant is created by a dedicated function. pub enum Model { KeyringListV0(keyring::ListV0), - WkdUrlV0(wkd::UrlV0), } impl Model { @@ -39,20 +37,6 @@ impl Model { v.unwrap_or(DEFAULT_OUTPUT_VERSION) } - /// Create a model for the output of `sq wkd url` and `sq wkd - /// direct-url` subcommands. - pub fn wkd_url(version: Option, - variant: wkd::WkdUrlVariant, - advanced_url: String, - direct_url: String) -> Result { - let version = Self::version(version); - let result = match version { - wkd::UrlV0::V => Self::WkdUrlV0(wkd::UrlV0::new(variant, advanced_url, direct_url)), - _ => return Err(anyhow!("unknown output version {:?}", version)), - }; - Ok(result) - } - /// Create a model for the output of the `sq toolbox keyring list` /// subcommand. pub fn keyring_list(version: Option, certs: Vec, all_uids: bool) -> Result { @@ -74,12 +58,6 @@ impl Model { _ => x.human_readable(w)?, } } - Self::WkdUrlV0(x) => { - match format { - OutputFormat::Json => x.json(w)?, - _ => x.human_readable(w)?, - } - } } Ok(()) } @@ -237,49 +215,3 @@ mod keyring { } } } - -// Model output as a data type that can be serialized. -pub mod wkd { - use super::{OutputVersion, Result, Write}; - use serde::Serialize; - - #[derive(Debug)] - pub enum WkdUrlVariant { - Advanced, - Direct, - } - - #[derive(Debug, Serialize)] - pub struct UrlV0 { - #[serde(skip)] - variant: WkdUrlVariant, - sq_output_version: OutputVersion, - advanced_url: String, - direct_url: String, - } - - impl UrlV0 { - pub const V: OutputVersion = OutputVersion::new(0, 0, 0); - - pub fn new(variant: WkdUrlVariant, advanced_url: String, direct_url: String) -> Self { - Self { - sq_output_version: Self::V, - variant, - advanced_url, - direct_url, - } - } - - pub fn human_readable(&self, w: &mut dyn Write) -> Result<()> { - match self.variant { - WkdUrlVariant::Advanced => writeln!(w, "{}", self.advanced_url)?, - WkdUrlVariant::Direct => writeln!(w, "{}", self.direct_url)?, - } - Ok(()) - } - - pub fn json(&self, w: &mut dyn Write) -> Result<()> { - super::to_json(w, self) - } - } -}