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(gateway): handle invalid project names in ScopedUser #1396

Merged
merged 4 commits into from
Nov 20, 2023
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
4 changes: 2 additions & 2 deletions common/src/models/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt::{Display, Formatter};

use crossterm::style::{Color, Stylize};
use crossterm::style::Stylize;
use http::StatusCode;
use serde::{Deserialize, Serialize};
use tracing::{error, warn};
Expand All @@ -23,7 +23,7 @@ impl Display for ApiError {
f,
"{}\nMessage: {}",
self.status().to_string().bold(),
self.message.to_string().with(Color::Red)
self.message.to_string().red()
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion gateway/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use axum::extract::{FromRef, FromRequestParts, Path};
use axum::http::request::Parts;
use serde::{Deserialize, Serialize};
use shuttle_common::claims::{Claim, Scope};
use shuttle_common::models::error::InvalidProjectName;
use shuttle_common::models::project::ProjectName;
use tracing::{trace, Span};

Expand Down Expand Up @@ -80,7 +81,7 @@ where
Err(_) => Path::<(ProjectName, String)>::from_request_parts(parts, state)
.await
.map(|Path((p, _))| p)
.unwrap(),
.map_err(|_| Error::from(ErrorKind::InvalidProjectName(InvalidProjectName)))?,
};

if user.projects.contains(&scope) || user.claim.scopes.contains(&Scope::Admin) {
Expand Down
6 changes: 3 additions & 3 deletions gateway/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl GatewayService {
.try_get::<SqlxJson<Project>, _>("project_state")
.map(|p| p.0)
.unwrap_or_else(|e| {
error!("Failed to deser `project_state`: {:?}", e);
error!(error = ?e, "Failed to deser `project_state`");
Project::Errored(ProjectError::internal(
"Error when trying to deserialize state of project.",
))
Expand Down Expand Up @@ -364,7 +364,7 @@ impl GatewayService {
row.try_get::<SqlxJson<Project>, _>("project_state")
.map(|p| p.0)
.unwrap_or_else(|e| {
error!("Failed to deser `project_state`: {:?}", e);
error!(error = ?e, "Failed to deser `project_state`");
Project::Errored(ProjectError::internal(
"Error when trying to deserialize state of project.",
))
Expand Down Expand Up @@ -459,7 +459,7 @@ impl GatewayService {
.try_get::<SqlxJson<Project>, _>("project_state")
.map(|p| p.0)
.unwrap_or_else(|e| {
error!("Failed to deser `project_state`: {:?}", e);
error!(error = ?e, "Failed to deser `project_state`");
Project::Errored(ProjectError::internal(
"Error when trying to deserialize state of project.",
))
Expand Down