Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/stakwork/sphinx-swarm
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Oct 24, 2024
2 parents 650c3eb + 7408549 commit 4188924
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/bin/super/checker.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::anyhow;
use anyhow::Result;
use rocket::tokio;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -88,7 +89,10 @@ pub async fn check_all_swarms() -> Result<()> {
}
}
Err(err) => {
log::error!("Unable to get boltwall and navfiber url: {}", err)
log::error!(
"Unable to get boltwall and navfiber url: {}",
err.to_string()
)
}
}
}
Expand All @@ -101,7 +105,16 @@ pub async fn check_all_swarms() -> Result<()> {
}

fn get_boltwall_and_navfiber_url(host: String) -> Result<(String, String)> {
if host.contains("swarm") {
let parts: Vec<&str> = host.split('.').collect();

if parts.len() < 3 {
log::error!("Invalid domain structure.");
return Err(anyhow!("Invalid domain structure."));
}

let subdomain = parts[0];

if subdomain.starts_with("swarm") && is_numeric(&subdomain[5..]) {
return Ok((
format!("https://nav.{}/", host.clone()),
format!("https://boltwall.{}/api/", host.clone()),
Expand All @@ -114,6 +127,10 @@ fn get_boltwall_and_navfiber_url(host: String) -> Result<(String, String)> {
));
}

fn is_numeric(s: &str) -> bool {
s.chars().all(|c| c.is_digit(10))
}

fn make_client() -> reqwest::Client {
reqwest::Client::builder()
.timeout(Duration::from_secs(20))
Expand Down

0 comments on commit 4188924

Please sign in to comment.