Skip to main content

systemprompt_cli/commands/cloud/tenant/create/
mod.rs

1//! Tenant creation flows for the `cloud tenant create` command.
2//!
3//! Routes to the cloud-subscription flow ([`create_cloud_tenant`]) or one of
4//! the local flows ([`create_local_tenant`] for a managed Docker container,
5//! [`create_external_tenant`] for a user-supplied database).
6//!
7//! Copyright (c) systemprompt.io — Business Source License 1.1.
8//! See <https://systemprompt.io> for licensing details.
9
10mod cloud;
11mod local;
12pub mod progress;
13
14pub use cloud::create_cloud_tenant;
15pub use local::{
16    create_external_tenant, create_local_tenant, handle_orphaned_volume, resolve_container_state,
17};
18pub use systemprompt_cloud::tenants::swap_to_external_host;
19
20fn sanitize_database_name(name: &str) -> String {
21    let sanitized: String = name
22        .chars()
23        .map(|c| {
24            if c.is_ascii_alphanumeric() || c == '_' {
25                c
26            } else {
27                '_'
28            }
29        })
30        .collect();
31
32    if sanitized.is_empty() {
33        "systemprompt".to_owned()
34    } else if sanitized.chars().next().is_some_and(|c| c.is_ascii_digit()) {
35        format!("db_{}", sanitized)
36    } else {
37        sanitized
38    }
39}