Compare commits

...
Author SHA1 Message Date
Brandon Thomas 4205aeedd8 cleanup server environment 2026-05-23 12:45:33 -04:00
68 changed files with 82 additions and 163 deletions
Generated
+5 -3
View File
@@ -357,7 +357,7 @@ dependencies = [
"actix-rt",
"actix-web",
"log",
"reusable_types",
"server_environment",
"speculoos",
"url",
"workspace-build-acceleration",
@@ -1492,6 +1492,7 @@ dependencies = [
"serde",
"serde_derive",
"serde_json",
"server_environment",
"sqlx",
"tokens",
"tokio",
@@ -1522,6 +1523,7 @@ dependencies = [
"serde",
"serde_derive",
"serde_json",
"server_environment",
"sqlx",
"tokio",
"url_config",
@@ -3610,10 +3612,10 @@ dependencies = [
"easyenv",
"errors",
"hostname 0.4.0",
"reusable_types",
"serde",
"serde_derive",
"serde_json",
"server_environment",
"workspace-build-acceleration",
]
@@ -13539,7 +13541,7 @@ dependencies = [
"actix-web",
"actix_helpers",
"anyhow",
"reusable_types",
"server_environment",
"workspace-build-acceleration",
]
+1
View File
@@ -274,6 +274,7 @@ pager = { path = "crates/lib/pager" }
openai_sora_client = { path = "crates/api_clients/openai_sora_client" }
primitives = { path = "crates/lib/data/primitives" }
seedance2pro_client = { path = "crates/api_clients/seedance2pro_client" }
server_environment = { path = "crates/lib/server_environment" }
shared_service_components = { path = "crates/lib/shared_service_components" }
sqlite_tasks = { path = "crates/schema/database/sqlite_tasks" }
subprocess_common = { path = "crates/lib/deprecated/subprocess_common" }
+1 -1
View File
@@ -20,7 +20,7 @@ normal = ["workspace-build-acceleration"]
workspace-build-acceleration = { workspace = true }
# Internal
reusable_types = { path = "../../schema/public/reusable_types" }
server_environment.workspace = true
# External
log = { workspace = true }
@@ -71,7 +71,7 @@ pub fn add_fakeyou_dev_proxy(cors: Cors, _is_production: bool) -> Cors {
#[cfg(test)]
mod tests {
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use crate::cors::build_cors_config;
use crate::testing::assert_origin_invalid;
@@ -59,7 +59,7 @@ pub fn add_storyteller_dev_proxy(cors: Cors, _is_production: bool) -> Cors {
#[cfg(test)]
mod tests {
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use crate::cors::build_cors_config;
use crate::testing::assert_origin_invalid;
@@ -18,7 +18,7 @@ pub fn add_storyteller_board(cors: Cors, _is_production: bool) -> Cors {
#[cfg(test)]
mod tests {
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use crate::cors::build_cors_config;
use crate::testing::assert_origin_invalid;
@@ -14,7 +14,7 @@ pub fn add_storyteller_render(cors: Cors, _is_production: bool) -> Cors {
#[cfg(test)]
mod tests {
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use crate::cors::build_cors_config;
use crate::testing::assert_origin_invalid;
@@ -18,7 +18,7 @@ pub fn add_storyteller_studio(cors: Cors, _is_production: bool) -> Cors {
#[cfg(test)]
mod tests {
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use crate::cors::build_cors_config;
use crate::testing::assert_origin_invalid;
+2 -2
View File
@@ -14,7 +14,7 @@ use crate::configs::storyteller_board::add_storyteller_board;
use crate::configs::storyteller_render::add_storyteller_render;
use crate::configs::storyteller_studio::add_storyteller_studio;
use crate::configs::tauri::add_tauri;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
/// Return cors config for FakeYou / Vocodes / OBS / local development
pub fn build_cors_config(server_environment: ServerEnvironment) -> Cors {
@@ -80,7 +80,7 @@ fn do_build_cors_config(is_production: bool) -> Cors {
#[cfg(test)]
mod tests {
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use crate::testing::assert_origin_invalid;
use crate::testing::assert_origin_ok;
+1 -1
View File
@@ -21,7 +21,7 @@ workspace-build-acceleration = { workspace = true }
# Internal
actix_helpers = { path = "../actix_helpers" }
reusable_types = { path = "../../schema/public/reusable_types" }
server_environment.workspace = true
# External
actix-web = { workspace = true }
@@ -5,7 +5,7 @@ use actix_web::HttpRequest;
use anyhow::anyhow;
use actix_helpers::extractors::get_request_host::get_request_host;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
/// Multi-environment configuration for 3rd party redirects, eg. Stripe checkout flow and
/// Twitch OAuth flow.
@@ -82,7 +82,7 @@ mod tests {
use actix_web::HttpRequest;
use actix_web::test::TestRequest;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use crate::third_party_url_redirector::ThirdPartyUrlRedirector;
@@ -18,5 +18,4 @@
#[cfg(test)] pub mod test_helpers;
pub mod achievements;
pub mod server_environment;
pub mod stripe;
@@ -1,69 +0,0 @@
/// The environmental context the server is operating in.
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub enum ServerEnvironment {
/// Development instances of our web services run on developer machines.
Development,
/// The production machines behind our web services.
Production,
// /// NB: Staging does not yet exist, and we sort of treat production as a semi-staging
// /// for frontend testing.
// Staging,
}
impl ServerEnvironment {
pub fn from_str(environment: &str) -> Option<ServerEnvironment> {
match environment {
"dev" | "DEV" | "development" | "DEVELOPMENT" => Some(ServerEnvironment::Development),
"prod" | "PROD" | "production" | "PRODUCTION" => Some(ServerEnvironment::Production),
// "stage" | "STAGE" | "staging" | "STAGING" => Some(ServerEnvironment::Staging),
_ => None,
}
}
/// Reports whether the software is running in production.
/// This is useful once proper "staging" backends gets introduced, as currently staging frontend
/// is served by the production backend.
pub fn is_deployed_in_production(&self) -> bool {
match self {
ServerEnvironment::Development => false,
ServerEnvironment::Production => true,
}
}
}
#[cfg(test)]
mod tests {
use crate::server_environment::ServerEnvironment;
#[test]
fn test_development_from_str() {
assert_eq!(ServerEnvironment::from_str("dev"), Some(ServerEnvironment::Development));
assert_eq!(ServerEnvironment::from_str("development"), Some(ServerEnvironment::Development));
assert_eq!(ServerEnvironment::from_str("DEV"), Some(ServerEnvironment::Development));
assert_eq!(ServerEnvironment::from_str("DEVELOPMENT"), Some(ServerEnvironment::Development));
}
#[test]
fn test_production_from_str() {
assert_eq!(ServerEnvironment::from_str("prod"), Some(ServerEnvironment::Production));
assert_eq!(ServerEnvironment::from_str("production"), Some(ServerEnvironment::Production));
assert_eq!(ServerEnvironment::from_str("PROD"), Some(ServerEnvironment::Production));
assert_eq!(ServerEnvironment::from_str("PRODUCTION"), Some(ServerEnvironment::Production));
}
#[test]
fn test_invalid() {
assert_eq!(ServerEnvironment::from_str(""), None);
assert_eq!(ServerEnvironment::from_str("develops"), None);
assert_eq!(ServerEnvironment::from_str("pRoDs"), None);
assert_eq!(ServerEnvironment::from_str("staging"), None);
}
#[test]
fn test_is_deployed_in_production() {
assert_eq!(true, ServerEnvironment::Production.is_deployed_in_production());
assert_eq!(false, ServerEnvironment::Development.is_deployed_in_production());
}
}
@@ -25,6 +25,7 @@ enums.workspace = true
errors.workspace = true
http_server_common = { path = "../../../lib/deprecated/http_server_common" }
mysql_queries = { path = "../../../schema/database/mysql_queries" }
server_environment.workspace = true
reusable_types = { path = "../../../schema/public/reusable_types" }
url_config = { path = "../../../lib/url_config" }
user_traits_component = { path = "../user_traits_component" }
@@ -1,7 +1,7 @@
use actix_web::web::Json;
use actix_web::{web, HttpRequest, HttpResponse};
use component_traits::traits::internal_user_lookup::InternalUserLookup;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use url_config::third_party_url_redirector::ThirdPartyUrlRedirector;
use user_traits_component::traits::internal_session_cache_purge::InternalSessionCachePurge;
use utoipa::ToSchema;
@@ -2,7 +2,7 @@ use actix_web::http::header;
use actix_web::web::Query;
use actix_web::{web, HttpRequest, HttpResponse};
use component_traits::traits::internal_user_lookup::InternalUserLookup;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use url_config::third_party_url_redirector::ThirdPartyUrlRedirector;
use user_traits_component::traits::internal_session_cache_purge::InternalSessionCachePurge;
@@ -4,7 +4,7 @@ use std::str::FromStr;
use actix_web::HttpRequest;
use component_traits::traits::internal_user_lookup::InternalUserLookup;
use log::{error, warn};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use stripe::{CheckoutSession, CheckoutSessionMode, CreateCheckoutSession, CreateCheckoutSessionAutomaticTax, CreateCheckoutSessionLineItems, CreateCheckoutSessionPaymentIntentData, CreateCheckoutSessionSubscriptionData, CustomerId};
use url_config::third_party_url_redirector::ThirdPartyUrlRedirector;
@@ -199,7 +199,7 @@ mod tests {
use mockall::predicate::*;
use tokio;
use component_traits::traits::internal_user_lookup::{MockInternalUserLookup, UserMetadata};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use url_config::third_party_url_redirector::ThirdPartyUrlRedirector;
use crate::stripe::http_endpoints::checkout::create::stripe_create_checkout_session_error::CreateCheckoutSessionError;
@@ -4,7 +4,7 @@ use std::fmt::{Display, Formatter};
#[cfg(test)]
use mockall::{automock, predicate::*};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
/// Errors for this component are not strongly typed.
#[derive(Debug)]
@@ -29,6 +29,7 @@ errors.workspace = true
http_headers.workspace = true
http_server_common = { path = "../../../lib/deprecated/http_server_common" }
mysql_queries = { path = "../../../schema/database/mysql_queries" }
server_environment.workspace = true
reusable_types = { path = "../../../schema/public/reusable_types" }
tokens.workspace = true
user_traits_component = { path = "../user_traits_component" }
@@ -1,7 +1,7 @@
use crate::configs::credits_packs::stripe_artcraft_credits_pack_info::StripeArtcraftCreditsPackInfo;
use crate::configs::credits_packs::stripe_artcraft_credits_pack_info_list::{ARTCRAFT_10000_PRODUCTION, ARTCRAFT_1000_PRODUCTION, ARTCRAFT_1000_SANDBOX, ARTCRAFT_25000_PRODUCTION, ARTCRAFT_2500_PRODUCTION, ARTCRAFT_2500_SANDBOX, ARTCRAFT_50000_PRODUCTION, ARTCRAFT_5000_PRODUCTION};
use enums::common::artcraft_credits_pack_slug::ArtcraftCreditsPackSlug;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
pub fn get_artcraft_credits_pack_by_slug_and_env(slug: ArtcraftCreditsPackSlug, env: ServerEnvironment) -> StripeArtcraftCreditsPackInfo {
match (env, slug) {
@@ -4,7 +4,7 @@ use crate::configs::stripe_artcraft_generic_product_info::StripeArtcraftGenericP
use crate::configs::subscriptions::stripe_artcraft_subscription_info::StripeArtcraftSubscriptionInfo;
use crate::configs::subscriptions::stripe_artcraft_subscription_info_list::{ARTCRAFT_BASIC_PRODUCTION, ARTCRAFT_BASIC_SANDBOX, ARTCRAFT_MAX_PRODUCTION, ARTCRAFT_MAX_SANDBOX, ARTCRAFT_PRO_PRODUCTION, ARTCRAFT_PRO_SANDBOX};
use once_cell::sync::Lazy;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use std::collections::HashMap;
static PRODUCTION_PRODUCTS_BY_STRIPE_ID : Lazy<HashMap<String, StripeArtcraftGenericProductInfo>> = Lazy::new(|| {
@@ -1,7 +1,7 @@
use crate::configs::subscriptions::stripe_artcraft_subscription_info::StripeArtcraftSubscriptionInfo;
use crate::configs::subscriptions::stripe_artcraft_subscription_info_list::{ARTCRAFT_BASIC_PRODUCTION, ARTCRAFT_BASIC_SANDBOX, ARTCRAFT_MAX_PRODUCTION, ARTCRAFT_MAX_SANDBOX, ARTCRAFT_PRO_PRODUCTION, ARTCRAFT_PRO_SANDBOX};
use enums::common::artcraft_subscription_slug::ArtcraftSubscriptionSlug;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
pub fn get_artcraft_subscription_by_slug_and_env(slug: ArtcraftSubscriptionSlug, env: ServerEnvironment) -> StripeArtcraftSubscriptionInfo {
match (env, slug) {
@@ -13,7 +13,7 @@ use enums::common::payments_namespace::PaymentsNamespace;
use log::{error, info, warn};
use mysql_queries::queries::users::user_stripe_customer_links::find_user_stripe_customer_link::find_user_stripe_customer_link_using_connection;
use mysql_queries::queries::users::user_subscriptions::find_subscription_for_owner_user::find_subscription_for_owner_user_using_connection;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use sqlx::MySqlPool;
use std::collections::HashMap;
use std::str::FromStr;
@@ -10,7 +10,7 @@ use enums::common::payments_namespace::PaymentsNamespace;
use log::{error, info, warn};
use mysql_queries::queries::users::user_subscriptions::find_possibly_inactive_first_subscription_for_owner_user::find_possibly_inactive_first_subscription_for_owner_user_using_connection;
use mysql_queries::queries::users::user_subscriptions::find_subscription_for_owner_user::find_subscription_for_owner_user_using_connection;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use sqlx::MySqlPool;
use std::collections::HashMap;
use std::str::FromStr;
@@ -20,7 +20,7 @@ use log::{error, info, warn};
use mysql_queries::queries::users::user_stripe_customer_links::find_user_stripe_customer_link::find_user_stripe_customer_link_using_connection;
use mysql_queries::queries::users::user_subscriptions::find_possibly_inactive_first_subscription_for_owner_user::find_possibly_inactive_first_subscription_for_owner_user_using_connection;
use mysql_queries::queries::users::user_subscriptions::find_subscription_for_owner_user::find_subscription_for_owner_user_using_connection;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use sqlx::MySqlPool;
use std::collections::HashMap;
use std::str::FromStr;
@@ -11,7 +11,7 @@ use component_traits::traits::internal_user_lookup::InternalUserLookup;
use enums::common::payments_namespace::PaymentsNamespace;
use log::{error, info, warn};
use mysql_queries::queries::users::user_subscriptions::find_subscription_for_owner_user::{find_subscription_for_owner_user_using_connection, UserSubscription};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use sqlx::MySqlPool;
use std::collections::HashMap;
use std::str::FromStr;
@@ -11,7 +11,7 @@ use component_traits::traits::internal_user_lookup::InternalUserLookup;
use enums::common::payments_namespace::PaymentsNamespace;
use log::{error, info, warn};
use mysql_queries::queries::users::user_subscriptions::find_subscription_for_owner_user::{find_subscription_for_owner_user_using_connection, UserSubscription};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use sqlx::MySqlPool;
use std::collections::HashMap;
use std::str::FromStr;
@@ -12,7 +12,7 @@ use component_traits::traits::internal_user_lookup::InternalUserLookup;
use enums::common::payments_namespace::PaymentsNamespace;
use log::{error, info, warn};
use mysql_queries::queries::users::user_subscriptions::find_subscription_for_owner_user::{find_subscription_for_owner_user_using_connection, UserSubscription};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use sqlx::MySqlPool;
use std::collections::HashMap;
use std::str::FromStr;
@@ -13,7 +13,7 @@ use component_traits::traits::internal_user_lookup::InternalUserLookup;
use enums::common::payments_namespace::PaymentsNamespace;
use log::{error, info, warn};
use mysql_queries::queries::users::user_subscriptions::find_subscription_for_owner_user::{find_subscription_for_owner_user_using_connection, UserSubscription};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use sqlx::MySqlPool;
use std::collections::HashMap;
use std::str::FromStr;
@@ -15,7 +15,7 @@ use log::{error, info, warn};
use mysql_queries::queries::billing::stripe::get_stripe_webhook_event_log_by_id::{get_stripe_webhook_event_log_by_id, get_stripe_webhook_event_log_by_id_with_connection};
use mysql_queries::queries::billing::stripe::insert_stripe_webhook_event_log::InsertStripeWebhookEventLog;
use mysql_queries::queries::users::user::update::maybe_update_email_from_synthetic_value::{maybe_update_email_from_synthetic_value, MaybeUpdateEmailFromSyntheticValueArgs};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use serde_derive::Serialize;
use sqlx::pool::PoolConnection;
use sqlx::{Acquire, MySql, MySqlConnection, MySqlPool, Transaction};
@@ -7,7 +7,7 @@ use crate::endpoints::webhook::common::webhook_event_log_summary::WebhookEventLo
use crate::endpoints::webhook::webhook_event_enrichment::customer_subscription::common::calculate_subscription_end_date::calculate_subscription_end_date;
use crate::endpoints::webhook::webhook_event_enrichment::customer_subscription::common::subscription_summary_extractor::subscription_summary_extractor;
use log::{error, warn};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use stripe_shared::Subscription;
pub struct EventLogAndSubscriptionDetails {
@@ -2,7 +2,7 @@ use crate::billing_action_fulfillment::artcraft_billing_action::ArtcraftBillingA
use crate::endpoints::webhook::common::enriched_webhook_event::EnrichedWebhookEvent;
use crate::endpoints::webhook::common::stripe_artcraft_webhook_error::StripeArtcraftWebhookError;
use crate::endpoints::webhook::webhook_event_enrichment::customer_subscription::common::extract_common_subscription_details::extract_common_subscription_details;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use stripe_shared::Subscription;
/// Handle event type: 'customer.subscription.created'
@@ -2,7 +2,7 @@ use crate::billing_action_fulfillment::artcraft_billing_action::ArtcraftBillingA
use crate::endpoints::webhook::common::enriched_webhook_event::EnrichedWebhookEvent;
use crate::endpoints::webhook::common::stripe_artcraft_webhook_error::StripeArtcraftWebhookError;
use crate::endpoints::webhook::webhook_event_enrichment::customer_subscription::common::extract_common_subscription_details::extract_common_subscription_details;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use stripe_shared::Subscription;
/// Handle event type: 'customer.subscription.deleted'
@@ -2,7 +2,7 @@ use crate::billing_action_fulfillment::artcraft_billing_action::ArtcraftBillingA
use crate::endpoints::webhook::common::enriched_webhook_event::EnrichedWebhookEvent;
use crate::endpoints::webhook::common::stripe_artcraft_webhook_error::StripeArtcraftWebhookError;
use crate::endpoints::webhook::webhook_event_enrichment::customer_subscription::common::extract_common_subscription_details::extract_common_subscription_details;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use stripe_shared::Subscription;
/// Handle event type: 'customer.subscription.updated'
@@ -10,7 +10,7 @@ use crate::endpoints::webhook::webhook_event_enrichment::invoice::invoice_paymen
use crate::endpoints::webhook::webhook_event_enrichment::payment_intent::payment_intent_succeeded_extractor::payment_intent_succeeded_extractor;
use crate::utils::stripe_event_descriptor::StripeEventDescriptor;
use log::{info, warn};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use sqlx::pool::PoolConnection;
use sqlx::{MySql, Transaction};
use stripe::Client;
@@ -10,7 +10,7 @@ use crate::utils::expand_ids::expand_subscription_id::expand_subscription_id;
use crate::utils::metadata::get_metadata_user_token::get_metadata_user_token;
use crate::utils::stripe_event_descriptor::StripeEventDescriptor;
use log::{error, info, warn};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use stripe::Client;
use stripe_shared::{Invoice, InvoiceBillingReason, InvoiceStatus};
use stripe_types::Expandable;
@@ -10,7 +10,7 @@ use crate::utils::expand_ids::expand_customer_id::expand_customer_id;
use crate::utils::metadata::get_metadata_user_token::get_metadata_user_token;
use crate::utils::metadata::get_metadata_wallet_token::get_metadata_wallet_token;
use log::{error, info, warn};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use sqlx::{MySql, Transaction};
use stripe::Client;
use stripe_checkout::checkout_session::ListCheckoutSession;
@@ -6,7 +6,7 @@ use errors::AnyhowResult;
use once_cell::sync::Lazy;
use http_server_common::request::get_request_ip::get_request_ip;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
/// List of IP addresses that send webhook requests
/// From: https://stripe.com/docs/ips
+1 -1
View File
@@ -24,7 +24,7 @@ actix_cors_configs = { path = "../../../lib/actix_cors_configs" }
actix_helpers = { path = "../../../lib/actix_helpers" }
easyenv = { path = "../../../lib/easyenv" }
errors = { workspace = true }
reusable_types = { path = "../../../schema/public/reusable_types" }
server_environment.workspace = true
# External
chrono = { workspace = true }
@@ -1,5 +1,5 @@
use errors::{anyhow, AnyhowResult};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
#[derive(Clone)]
pub struct EnvArgs {
@@ -1,5 +1,5 @@
use billing_component::stripe::traits::internal_product_to_stripe_lookup::{InternalProductToStripeLookup, StripeProduct, StripeProductLookupError};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use crate::configs::plans::plan_list::{DEVELOPMENT_PREMIUM_PLANS_BY_SLUG, PRODUCTION_PREMIUM_PLANS_BY_SLUG};
@@ -1,7 +1,7 @@
use crate::configs::artcraft_products::stripe_artcraft_product_info::StripeArtcraftProductInfo;
use crate::configs::artcraft_products::stripe_artcraft_product_info_list::{ARTCRAFT_BASIC_PRODUCTION, ARTCRAFT_BASIC_SANDBOX, ARTCRAFT_MAX_PRODUCTION, ARTCRAFT_MAX_SANDBOX, ARTCRAFT_PRO_PRODUCTION, ARTCRAFT_PRO_SANDBOX};
use enums::common::artcraft_subscription_slug::ArtcraftSubscriptionSlug;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
pub fn get_artcraft_product_by_slug(slug: ArtcraftSubscriptionSlug, env: ServerEnvironment) -> StripeArtcraftProductInfo {
match (env, slug) {
@@ -1,7 +1,7 @@
use chrono::Utc;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use crate::configs::plans::plan::Plan;
use crate::configs::plans::plan_list::{DEVELOPMENT_PREMIUM_PLANS_BY_SLUG, FREE_LOGGED_IN_PLAN, FREE_LOGGED_OUT_PLAN, LOYALTY_PLANS_BY_SLUG, PRODUCTION_PREMIUM_PLANS_BY_SLUG};
@@ -66,7 +66,7 @@ pub mod tests {
use chrono::{Duration, Utc};
use enums::common::payments_namespace::PaymentsNamespace;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use crate::configs::plans::get_correct_plan_for_session::get_correct_plan_for_session;
use crate::configs::plans::plan_list::{ALL_PLANS_BY_SLUG, FREE_LOGGED_IN_PLAN, FREE_LOGGED_OUT_PLAN};
@@ -189,7 +189,7 @@ pub async fn enqueue_face_animation_handler(
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref());
// TODO: Separate priority for animation.
@@ -130,7 +130,7 @@ pub async fn enqueue_rerender_animation_handler(
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref());
// TODO: Separate priority for animation.
@@ -145,7 +145,7 @@ pub async fn enqueue_fbx_to_gltf_handler(
// Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref()
);
@@ -178,7 +178,7 @@ pub async fn enqueue_render_engine_scene_to_video_handler(
// Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref()
);
@@ -234,7 +234,7 @@ pub async fn enqueue_image_generation_request(
// Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref()
);
@@ -125,7 +125,7 @@ pub async fn enqueue_mocapnet_handler(
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref());
// TODO: Separate priority for animation.
@@ -163,7 +163,7 @@ pub async fn enqueue_face_fusion_workflow_handler(
// ==================== PAID PLAN + PRIORITY ==================== //
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(server_state.server_environment_old, Some(&user_session));
let plan = get_correct_plan_for_session(server_state.server_environment, Some(&user_session));
// TODO: Separate priority for animation.
let priority_level = plan.web_vc_base_priority_level();
@@ -171,7 +171,7 @@ pub async fn enqueue_live_portrait_workflow_handler(
// ==================== PAID PLAN + PRIORITY ==================== //
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(server_state.server_environment_old, Some(&user_session));
let plan = get_correct_plan_for_session(server_state.server_environment, Some(&user_session));
// TODO: Separate priority for animation.
let priority_level = plan.web_vc_base_priority_level();
@@ -125,7 +125,7 @@ pub async fn enqueue_studio_workflow_handler(
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref());
// TODO: Separate priority for animation.
@@ -126,7 +126,7 @@ pub async fn enqueue_video_style_transfer_workflow_handler(
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref());
// TODO: Separate priority for animation.
@@ -150,7 +150,7 @@ pub async fn enqueue_comfy_ui_handler(
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref());
// TODO: Separate priority for animation.
@@ -227,7 +227,7 @@ pub async fn enqueue_comfy_ui_handler(
// Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref()
);
@@ -272,7 +272,7 @@ pub async fn enqueue_video_style_transfer_handler(
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref());
// TODO: Separate priority for animation.
@@ -155,7 +155,7 @@ pub async fn enqueue_workflow_upload_request(
// Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref()
);
@@ -123,7 +123,7 @@ pub async fn enqueue_gptsovits_model_download_handler(
// ==================== PAID PLAN + PRIORITY ==================== //
let plan = get_correct_plan_for_session(server_state.server_environment_old, Some(&user_session));
let plan = get_correct_plan_for_session(server_state.server_environment, Some(&user_session));
let priority_level = plan.web_vc_base_priority_level();
// ==================== DEBUG MODE + ROUTING TAG ==================== //
@@ -182,7 +182,7 @@ pub async fn enqueue_studio_gen2_handler(
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref());
// TODO: Separate priority for animation.
@@ -175,7 +175,7 @@ pub async fn enqueue_infer_f5_tts_handler(
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref());
priority_level = plan.tts_base_priority_level();
@@ -192,7 +192,7 @@ pub async fn enqueue_infer_tts_handler(
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref());
priority_level = plan.tts_base_priority_level();
@@ -157,7 +157,7 @@ pub async fn enqueue_infer_seed_vc_handler(
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref());
priority_level = plan.tts_base_priority_level();
@@ -194,7 +194,7 @@ pub async fn enqueue_voice_conversion_inference_handler(
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref());
priority_level = plan.web_vc_base_priority_level();
@@ -142,7 +142,7 @@ pub async fn enqueue_tts_request(
// Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref()
);
@@ -125,7 +125,7 @@ pub async fn create_voice_handler(
// TODO: Plan should handle "first anonymous use" and "investor" cases.
let plan = get_correct_plan_for_session(
server_state.server_environment_old,
server_state.server_environment,
maybe_user_session.as_ref()
);
@@ -4,7 +4,7 @@ use actix_web::dev::{ServiceRequest, ServiceResponse};
use actix_web::error::Error;
use actix_web::App;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use crate::http_server::routes::application_routes::add_application_routes::add_application_routes;
use crate::http_server::routes::legacy_routes::add_legacy_routes::add_legacy_routes;
+5 -11
View File
@@ -35,7 +35,7 @@ use bootstrap::bootstrap::{bootstrap, BootstrapArgs};
use component_traits::traits::internal_user_lookup::InternalUserLookup;
use errors::AnyhowResult;
use log::{info, warn};
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use shared_env_var_config::logging::DEFAULT_RUST_LOG;
use tokio::runtime::Runtime;
use user_traits_component::traits::internal_session_cache_purge::InternalSessionCachePurge;
@@ -193,12 +193,7 @@ pub async fn serve(
let num_workers = server_state.env_config.num_workers;
let hostname = server_state.hostname.clone();
// TODO(bt,2023-11-12): Remove the old type.
let old_server_environment = server_state.server_environment_old;
let new_server_environment = match old_server_environment {
ServerEnvironment::Development => server_environment::ServerEnvironment::Development,
ServerEnvironment::Production => server_environment::ServerEnvironment::Production,
};
let server_environment = server_state.server_environment;
let paging_flags_for_middleware = server_state.flags.paging.clone();
let pager_for_middleware = server_state.pager.clone();
@@ -247,8 +242,7 @@ pub async fn serve(
.app_data(web::Data::new(server_state_arc.third_party_url_redirector))
.app_data(web::Data::new(server_state_arc.google_sign_in_cert.clone()))
.app_data(web::Data::new(server_state_arc.pager.clone()))
.app_data(web::Data::new(old_server_environment))
.app_data(web::Data::new(new_server_environment))
.app_data(web::Data::new(server_environment))
.app_data(web::Data::from(product_lookup)) // NB: Data::from(Arc<T>) for dynamic dispatch
.app_data(web::Data::from(stripe_lookup)) // NB: Data::from(Arc<T>) for dynamic dispatch
.app_data(web::Data::from(user_lookup)) // NB: Data::from(Arc<T>) for dynamic dispatch
@@ -262,7 +256,7 @@ pub async fn serve(
.error_handler(handle_multipart_error)
)
.wrap(MetricsMiddleware::new(metrics_collector.clone()))
.wrap(build_cors_config(old_server_environment))
.wrap(build_cors_config(server_environment))
.wrap(shared_array_buffer_cors())
.wrap(DefaultHeaders::new()
.header("X-Backend-Hostname", &hostname)
@@ -280,7 +274,7 @@ pub async fn serve(
.exclude("/readiness"))
.wrap(middleware::Compress::default());
add_routes(app, old_server_environment)
add_routes(app, server_environment)
})
.bind(&bind_address)
.unwrap_or_else(|err| {
@@ -19,7 +19,7 @@ use opaque_cursors::v2::opaque_cursor_encoder_v2::OpaqueCursorEncoderV2;
use pager::worker::pager_worker::PagerWorker;
use redis::Client;
use redis_caching::redis_ttl_cache::RedisTtlCache;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use shared_env_var_config::redis::env_get_redis_0_connection_string_or_default;
use sqlx::MySqlPool;
use url_config::third_party_url_redirector::ThirdPartyUrlRedirector;
@@ -185,12 +185,7 @@ pub async fn setup_dependencies(server_hostname: &str) -> AnyhowResult<SetupResu
let server_environment = ServerEnvironment::from_str(&easyenv::get_env_string_required("SERVER_ENVIRONMENT")?)
.ok_or(anyhow!("invalid server environment"))?;
let server_environment_typed = match server_environment {
ServerEnvironment::Production => server_environment::ServerEnvironment::Production,
ServerEnvironment::Development => server_environment::ServerEnvironment::Development,
};
let (pager, pager_worker, paging_flags) = build_pager(server_environment_typed, server_hostname);
let (pager, pager_worker, paging_flags) = build_pager(server_environment, server_hostname);
let service_feature_flags = setup_static_feature_flags(paging_flags)?;
@@ -228,8 +223,7 @@ pub async fn setup_dependencies(server_hostname: &str) -> AnyhowResult<SetupResu
stripe_artcraft: setup_stripe_artcraft()?,
hostname: server_hostname.to_string(),
startup_time,
server_environment_old: server_environment,
server_environment: server_environment_typed,
server_environment,
flags: service_feature_flags,
third_party_url_redirector,
health_check_status,
@@ -39,7 +39,7 @@ use opaque_cursors::v2::opaque_cursor_encoder_v2::OpaqueCursorEncoderV2;
use pager::client::pager::Pager;
use redis::Client;
use redis_caching::redis_ttl_cache::RedisTtlCache;
use reusable_types::server_environment::ServerEnvironment;
use server_environment::ServerEnvironment;
use sqlx::MySqlPool;
use url_config::third_party_url_redirector::ThirdPartyUrlRedirector;
@@ -58,12 +58,8 @@ pub struct ServerState {
/// When the server starts.
pub startup_time: DateTime<Utc>,
#[deprecated(note = "Use `server_environment` instead")]
/// Knowing if we're in production will allow us to turn off development-only functionalities.
pub server_environment_old: ServerEnvironment,
/// Knowing if we're in production will allow us to turn off development-only functionalities.
pub server_environment: server_environment::ServerEnvironment,
pub server_environment: ServerEnvironment,
/// Feature flags will allow us to restart the service with different conditions embedded in the code.
pub flags: StaticFeatureFlags,