Skip to content

Commit

Permalink
fix: wrap around common::ProjectName for parsing (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
brokad authored Nov 3, 2022
1 parent 6c848bf commit bd0c381
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] }
Expand Down
12 changes: 3 additions & 9 deletions gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,8 +27,6 @@ pub mod worker;

use crate::service::{ContainerSettings, GatewayService};

static PROJECT_REGEX: Lazy<Regex> = 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.
///
Expand Down Expand Up @@ -126,11 +122,9 @@ impl FromStr for ProjectName {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
if PROJECT_REGEX.is_match(s) {
Ok(Self(s.to_string()))
} else {
Err(Error::from_kind(ErrorKind::InvalidProjectName))
}
s.parse::<shuttle_common::project::ProjectName>()
.map_err(|_| Error::from_kind(ErrorKind::InvalidProjectName))
.map(|pn| Self(pn.to_string()))
}
}

Expand Down

0 comments on commit bd0c381

Please sign in to comment.