Skip to content

Commit

Permalink
feat: linux
Browse files Browse the repository at this point in the history
  • Loading branch information
pxseu committed Oct 8, 2023
1 parent 3384527 commit f8f6d4e
Show file tree
Hide file tree
Showing 10 changed files with 389 additions and 401 deletions.
23 changes: 6 additions & 17 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions src/commands/ignite/from_compose/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,8 @@ impl<'de> Deserialize<'de> for HealthCheckTest {
let value = Value::deserialize(deserializer)?;

// regex to extract the hostname port and path from a given curl command
let re =
Regex::new(r#"^curl\s?((?:-|--)[A-Za-z]+)*\s+(https?://)?([^/:\s]+)(:\d+)?(/.*)?$"#)
.unwrap();
let re = Regex::new(r"^curl\s?((?:-|--)[A-Za-z]+)*\s+(https?://)?([^/:\s]+)(:\d+)?(/.*)?$")
.unwrap();

let test_string = match value {
Value::String(s) => s,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/tunnel/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ impl TonneruSocket {

#[cfg(not(windows))]
let config = {
// ref: https://github.com/rustls/hyper-rustls/blob/main/src/config.rs#L55
// ref: https://github.com/rustls/hyper-rustls/blob/fcb72be6e3b0e060bfe5bc183a67c16ea56e7132/src/config.rs#L55-L69
let mut roots = RootCertStore::empty();
roots.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| {
roots.add_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.iter().map(|ta| {
OwnedTrustAnchor::from_subject_spki_name_constraints(
ta.subject,
ta.spki,
Expand Down
168 changes: 84 additions & 84 deletions src/commands/webhooks/create.rs
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
use anyhow::{Context, Result};
use clap::Parser;
use hop::webhooks::types::{PossibleEvents, EVENT_CATEGORIES, EVENT_NAMES};

use super::utils::string_to_event;
use crate::state::State;
use crate::utils::urlify;

#[derive(Debug, Parser)]
#[clap(about = "Create a new webhook")]
#[group(skip)]
pub struct Options {
#[clap(short, long, help = "The url to send the webhook to")]
pub url: Option<String>,
#[clap(short, long, help = "The events to send the webhook on", value_parser = string_to_event )]
pub events: Vec<PossibleEvents>,
}

pub async fn handle(options: Options, state: State) -> Result<()> {
let project = state.ctx.current_project_error()?;

let url = if let Some(url) = options.url {
url
} else {
dialoguer::Input::new()
.with_prompt("Webhook URL")
.interact_text()?
};

let events = if !options.events.is_empty() {
options.events
} else {
let mut events = vec![];
let mut start_idx = 0usize;

for (name, end_idx) in EVENT_CATEGORIES {
let end_idx = end_idx as usize + start_idx;

for (_, event) in &EVENT_NAMES[start_idx..end_idx] {
events.push(format!("{name}: {event}"))
}

start_idx = end_idx;
}

let dialoguer_events = loop {
let test = dialoguer::MultiSelect::new()
.with_prompt("Select events")
.items(&events)
.interact()?;

if !test.is_empty() {
break test;
}
};

EVENT_NAMES
.into_iter()
.enumerate()
.filter(|(idx, _)| dialoguer_events.contains(idx))
.map(|(_, (event, _))| event)
.collect()
};

let webhook = state
.hop
.webhooks
.create(&project.id, &url, &events)
.await?;

log::info!("Webhook successfully created. ID: {}\n", webhook.id);
log::info!("This is your webhook's secret, this is how you will authenticate traffic coming to your endpoint");
log::info!("Webhook Header: {}", urlify("X-Hop-Hooks-Signature"));
log::info!(
"Webhook Secret: {}",
urlify(
&webhook
.secret
.context("Webhook secret was expected to be present")?
)
);

Ok(())
}
use anyhow::{Context, Result};
use clap::Parser;
use hop::webhooks::types::{PossibleEvents, EVENT_CATEGORIES, EVENT_NAMES};

use super::utils::string_to_event;
use crate::state::State;
use crate::utils::urlify;

#[derive(Debug, Parser)]
#[clap(about = "Create a new webhook")]
#[group(skip)]
pub struct Options {
#[clap(short, long, help = "The url to send the webhook to")]
pub url: Option<String>,
#[clap(short, long, help = "The events to send the webhook on", value_parser = string_to_event )]
pub events: Vec<PossibleEvents>,
}

pub async fn handle(options: Options, state: State) -> Result<()> {
let project = state.ctx.current_project_error()?;

let url = if let Some(url) = options.url {
url
} else {
dialoguer::Input::new()
.with_prompt("Webhook URL")
.interact_text()?
};

let events = if !options.events.is_empty() {
options.events
} else {
let mut events = vec![];
let mut start_idx = 0usize;

for (name, end_idx) in EVENT_CATEGORIES {
let end_idx = end_idx as usize + start_idx;

for (_, event) in &EVENT_NAMES[start_idx..end_idx] {
events.push(format!("{name}: {event}"))
}

start_idx = end_idx;
}

let dialoguer_events = loop {
let test = dialoguer::MultiSelect::new()
.with_prompt("Select events")
.items(&events)
.interact()?;

if !test.is_empty() {
break test;
}
};

EVENT_NAMES
.into_iter()
.enumerate()
.filter(|(idx, _)| dialoguer_events.contains(idx))
.map(|(_, (event, _))| event)
.collect()
};

let webhook = state
.hop
.webhooks
.create(&project.id, &url, &events)
.await?;

log::info!("Webhook successfully created. ID: {}\n", webhook.id);
log::info!("This is your webhook's secret, this is how you will authenticate traffic coming to your endpoint");
log::info!("Webhook Header: {}", urlify("X-Hop-Hooks-Signature"));
log::info!(
"Webhook Secret: {}",
urlify(
&webhook
.secret
.context("Webhook secret was expected to be present")?
)
);

Ok(())
}
78 changes: 39 additions & 39 deletions src/commands/webhooks/delete.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
use anyhow::{Context, Result};
use clap::Parser;

use crate::commands::webhooks::utils::format_webhooks;
use crate::state::State;

#[derive(Debug, Parser)]
#[clap(about = "Delete a webhook")]
#[group(skip)]
pub struct Options {
#[clap(short, long, help = "The id of the webhook")]
pub id: Option<String>,
}

pub async fn handle(options: Options, state: State) -> Result<()> {
let project = state.ctx.current_project_error()?;

let all = state.hop.webhooks.get_all(&project.id).await?;

let webhook = if let Some(id) = options.id {
all.into_iter()
.find(|webhook| webhook.id == id)
.context("Webhook not found")?
} else {
let formatted_webhooks = format_webhooks(&all, false);

let idx = dialoguer::Select::new()
.with_prompt("Select a webhook to update")
.items(&formatted_webhooks)
.default(0)
.interact()?;

all[idx].clone()
};

state.hop.webhooks.delete(&project.id, &webhook.id).await?;

Ok(())
}
use anyhow::{Context, Result};
use clap::Parser;

use crate::commands::webhooks::utils::format_webhooks;
use crate::state::State;

#[derive(Debug, Parser)]
#[clap(about = "Delete a webhook")]
#[group(skip)]
pub struct Options {
#[clap(short, long, help = "The id of the webhook")]
pub id: Option<String>,
}

pub async fn handle(options: Options, state: State) -> Result<()> {
let project = state.ctx.current_project_error()?;

let all = state.hop.webhooks.get_all(&project.id).await?;

let webhook = if let Some(id) = options.id {
all.into_iter()
.find(|webhook| webhook.id == id)
.context("Webhook not found")?
} else {
let formatted_webhooks = format_webhooks(&all, false);

let idx = dialoguer::Select::new()
.with_prompt("Select a webhook to update")
.items(&formatted_webhooks)
.default(0)
.interact()?;

all[idx].clone()
};

state.hop.webhooks.delete(&project.id, &webhook.id).await?;

Ok(())
}
70 changes: 35 additions & 35 deletions src/commands/webhooks/list.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
use anyhow::Result;
use clap::Parser;

use super::utils::format_webhooks;
use crate::state::State;

#[derive(Debug, Parser)]
#[clap(about = "List webhooks")]
#[group(skip)]
pub struct Options {
#[clap(short, long, help = "Only print the IDs")]
pub quiet: bool,
}

pub async fn handle(options: Options, state: State) -> Result<()> {
let project = state.ctx.current_project_error()?;

let webhooks = state.hop.webhooks.get_all(&project.id).await?;

if options.quiet {
let ids = webhooks
.iter()
.map(|d| d.id.as_str())
.collect::<Vec<_>>()
.join(" ");

println!("{ids}");
} else {
let webhooks_fmt = format_webhooks(&webhooks, true);

println!("{}", webhooks_fmt.join("\n"));
}

Ok(())
}
use anyhow::Result;
use clap::Parser;

use super::utils::format_webhooks;
use crate::state::State;

#[derive(Debug, Parser)]
#[clap(about = "List webhooks")]
#[group(skip)]
pub struct Options {
#[clap(short, long, help = "Only print the IDs")]
pub quiet: bool,
}

pub async fn handle(options: Options, state: State) -> Result<()> {
let project = state.ctx.current_project_error()?;

let webhooks = state.hop.webhooks.get_all(&project.id).await?;

if options.quiet {
let ids = webhooks
.iter()
.map(|d| d.id.as_str())
.collect::<Vec<_>>()
.join(" ");

println!("{ids}");
} else {
let webhooks_fmt = format_webhooks(&webhooks, true);

println!("{}", webhooks_fmt.join("\n"));
}

Ok(())
}

0 comments on commit f8f6d4e

Please sign in to comment.