Skip to content

Commit

Permalink
bug: use correct project name
Browse files Browse the repository at this point in the history
  • Loading branch information
chesedo committed Nov 8, 2022
1 parent 3c8ede6 commit ff55462
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
12 changes: 10 additions & 2 deletions deployer/src/handlers/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use async_trait::async_trait;
use axum::extract::{FromRequest, Path, RequestParts};
use hyper::StatusCode;
use shuttle_common::project::ProjectName;
use tracing::error;

/// Gaurd to ensure request are for the project served by this deployer
/// Note: this guard needs the `ProjectName` extension to be set
Expand All @@ -26,18 +27,25 @@ where
// All our routes have the `project_name` parameter
let project_name = match path.get("project_name") {
Some(project_name) => project_name,
None => return Err(StatusCode::INTERNAL_SERVER_ERROR),
None => {
error!("ProjectNameGuard found no project name in path");
return Err(StatusCode::INTERNAL_SERVER_ERROR);
}
};

// This extractor requires the ProjectName extension to be set
let expected_project_name: &ProjectName = match req.extensions().get() {
Some(expected) => expected,
None => return Err(StatusCode::INTERNAL_SERVER_ERROR),
None => {
error!("ProjectName extension is not set");
return Err(StatusCode::INTERNAL_SERVER_ERROR);
}
};

if project_name == expected_project_name.as_str() {
Ok(ProjectNameGuard)
} else {
error!(project_name, "project is not served by this deployer");
Err(StatusCode::BAD_REQUEST)
}
}
Expand Down
14 changes: 5 additions & 9 deletions gateway/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ impl ProjectCreating {
"Image": image,
"Hostname": format!("{prefix}{project_name}"),
"Labels": {
"shuttle_prefix": prefix
"shuttle_prefix": prefix,
"project.name": project_name,
},
"Cmd": [
"--admin-secret",
Expand All @@ -413,10 +414,7 @@ impl ProjectCreating {
],
"Env": [
"RUST_LOG=debug",
],
"Labels": {
"project.name": project_name,
}
]
});

let mut config = Config::<String>::from(container_config);
Expand Down Expand Up @@ -619,9 +617,7 @@ pub struct Service {

impl Service {
pub fn from_container(container: ContainerInspectResponse) -> Result<Self, ProjectError> {
let container_name = safe_unwrap!(container.name.strip_prefix("/")).to_string();

let resource_name = safe_unwrap!(container_name.strip_suffix("_run")).to_string();
let name = safe_unwrap!(container.config.labels.get("project.name")).to_string();

let network = safe_unwrap!(container.network_settings.networks)
.values()
Expand All @@ -630,7 +626,7 @@ impl Service {
let target = safe_unwrap!(network.ip_address).parse().unwrap();

Ok(Self {
name: resource_name,
name,
target,
last_check: None,
})
Expand Down

0 comments on commit ff55462

Please sign in to comment.