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

feat: orgs #1720

Merged
merged 10 commits into from
Apr 5, 2024
7 changes: 7 additions & 0 deletions common/src/models/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ pub enum ErrorKind {
DeleteProjectFailed,
#[error("Our server is at capacity and cannot serve your request at this time. Please try again in a few minutes.")]
CapacityLimit,
#[error("{0:?}")]
InvalidOrganizationName(InvalidOrganizationName),
}

impl From<ErrorKind> for ApiError {
Expand Down Expand Up @@ -130,6 +132,7 @@ impl From<ErrorKind> for ApiError {
ErrorKind::NotReady => StatusCode::INTERNAL_SERVER_ERROR,
ErrorKind::DeleteProjectFailed => StatusCode::INTERNAL_SERVER_ERROR,
ErrorKind::CapacityLimit => StatusCode::SERVICE_UNAVAILABLE,
ErrorKind::InvalidOrganizationName(_) => StatusCode::BAD_REQUEST,
};
Self {
message: kind.to_string(),
Expand Down Expand Up @@ -190,3 +193,7 @@ impl From<StatusCode> for ApiError {
6. not be a reserved word."
)]
pub struct InvalidProjectName;

#[derive(Debug, Clone, PartialEq, thiserror::Error)]
#[error("Invalid organization name. Organization names must less than 30 characters.")]
chesedo marked this conversation as resolved.
Show resolved Hide resolved
pub struct InvalidOrganizationName;
8 changes: 7 additions & 1 deletion gateway/src/api/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use shuttle_backends::project_name::ProjectName;
use shuttle_backends::request_span;
use shuttle_backends::ClaimExt;
use shuttle_common::claims::{Scope, EXP_MINUTES};
use shuttle_common::models::error::ErrorKind;
use shuttle_common::models::error::{ErrorKind, InvalidOrganizationName};
use shuttle_common::models::{admin::ProjectResponse, project, stats};
use shuttle_common::models::{organization, service};
use shuttle_common::{deployment, VersionInfo};
Expand Down Expand Up @@ -492,6 +492,12 @@ async fn create_organization(
CustomErrorPath(organization_name): CustomErrorPath<String>,
chesedo marked this conversation as resolved.
Show resolved Hide resolved
User { id, .. }: User,
) -> Result<String, Error> {
if organization_name.len() > 30 {
chesedo marked this conversation as resolved.
Show resolved Hide resolved
return Err(Error::from_kind(ErrorKind::InvalidOrganizationName(
InvalidOrganizationName,
)));
}

let org = Organization {
id: format!("org_{}", Ulid::new()),
display_name: organization_name.clone(),
Expand Down