Skip to content

Commit

Permalink
fix(gateway): handle invalid project names in ScopedUser (#1396)
Browse files Browse the repository at this point in the history
* fix(gateway): handle invalid project names in ScopedUser

* nit: warn event is excessive

* clippy moment

* nit: better tracing error
  • Loading branch information
jonaro00 authored Nov 20, 2023
1 parent d9c015c commit e9ec21b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
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

0 comments on commit e9ec21b

Please sign in to comment.