From bd0c381c79c6144d828bc7856d08b4c0fe085acf Mon Sep 17 00:00:00 2001 From: Damien Date: Thu, 3 Nov 2022 08:50:11 +0000 Subject: [PATCH] fix: wrap around common::ProjectName for parsing (#451) --- Cargo.lock | 1 - gateway/Cargo.toml | 1 - gateway/src/lib.rs | 12 +++--------- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 584fb54aa..670bab1a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5403,7 +5403,6 @@ dependencies = [ "opentelemetry-http", "portpicker", "rand 0.8.5", - "regex", "serde", "serde_json", "shuttle-common", diff --git a/gateway/Cargo.toml b/gateway/Cargo.toml index 0c8e54807..b4de29c4c 100644 --- a/gateway/Cargo.toml +++ b/gateway/Cargo.toml @@ -22,7 +22,6 @@ opentelemetry = { version = "0.18.0", features = ["rt-tokio"] } opentelemetry-datadog = { version = "0.6.0", features = ["reqwest-client"] } opentelemetry-http = "0.7.0" rand = "0.8.5" -regex = "1.5.5" serde = { version = "1.0.137", features = [ "derive" ] } serde_json = "1.0.81" sqlx = { version = "0.5.11", features = [ "sqlite", "json", "runtime-tokio-rustls", "migrate" ] } diff --git a/gateway/src/lib.rs b/gateway/src/lib.rs index 6a99be184..702089243 100644 --- a/gateway/src/lib.rs +++ b/gateway/src/lib.rs @@ -12,8 +12,6 @@ use axum::response::{IntoResponse, Response}; use axum::Json; use bollard::Docker; use futures::prelude::*; -use once_cell::sync::Lazy; -use regex::Regex; use serde::{Deserialize, Deserializer, Serialize}; use shuttle_common::models::error::{ApiError, ErrorKind}; use tokio::sync::mpsc::error::SendError; @@ -29,8 +27,6 @@ pub mod worker; use crate::service::{ContainerSettings, GatewayService}; -static PROJECT_REGEX: Lazy = Lazy::new(|| Regex::new("^[a-zA-Z0-9\\-_]{3,64}$").unwrap()); - /// Server-side errors that do not have to do with the user runtime /// should be [`Error`]s. /// @@ -126,11 +122,9 @@ impl FromStr for ProjectName { type Err = Error; fn from_str(s: &str) -> Result { - if PROJECT_REGEX.is_match(s) { - Ok(Self(s.to_string())) - } else { - Err(Error::from_kind(ErrorKind::InvalidProjectName)) - } + s.parse::() + .map_err(|_| Error::from_kind(ErrorKind::InvalidProjectName)) + .map(|pn| Self(pn.to_string())) } }