Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrap around common::ProjectName for parsing #451

Merged
merged 2 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
brokad marked this conversation as resolved.
Show resolved Hide resolved
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