stackless_integrations/providers/railway/
hosting.rs1use std::collections::BTreeMap;
4
5use serde::Serialize;
6use stackless_stripe_projects::catalog::verify::CatalogService;
7use stackless_stripe_projects::provision::ProvisionContext;
8
9use super::FamilyResource;
10use crate::error::IntegrationError;
11use crate::hostable::{ConfigScope, Hostable, IntegrationHosting};
12
13pub const RESOURCE_KIND: &str = "integration-railway-hosting";
14
15pub const OUTPUT_FIELDS: &[(&str, &str, bool)] = &[
18 ("URL", "url", true),
19 ("DOMAIN", "domain", false),
20 ("DASHBOARD_URL", "dashboard_url", false),
21 ("TYPE", "type", false),
22];
23
24pub const OUTPUTS: &[&str] = &["url", "domain", "dashboard_url", "type"];
25
26#[derive(Debug, Serialize)]
27pub struct RailwayHostingConfig {}
28
29impl CatalogService for RailwayHostingConfig {
30 const REFERENCE: &'static str = "railway/hosting";
31}
32
33#[derive(Debug)]
34pub struct RailwayHosting;
35
36impl Hostable for RailwayHosting {
37 const PROVIDER: &'static str = "railway-hosting";
38 const HOSTING: IntegrationHosting = IntegrationHosting::Managed;
39 const CONFIG_SCOPE: ConfigScope = ConfigScope::GlobalOnly;
40 const RESOURCE_KIND: &'static str = RESOURCE_KIND;
41 const OUTPUTS: &'static [&'static str] = OUTPUTS;
42}
43
44impl FamilyResource for RailwayHosting {
45 type Config = RailwayHostingConfig;
46 const PROVIDER_PREFIX: &'static str = "RAILWAY";
47 const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] = OUTPUT_FIELDS;
48
49 fn build_config(ctx: &ProvisionContext<'_>) -> Result<RailwayHostingConfig, IntegrationError> {
50 let _ = super::integration_config(ctx)?;
51 Ok(RailwayHostingConfig {})
52 }
53}
54
55pub fn validate_config(
56 name: &str,
57 config: &BTreeMap<String, toml::Value>,
58) -> Result<(), IntegrationError> {
59 let _ = (name, config);
60 Ok(())
61}
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66 use crate::ProviderOps;
67 use crate::resource::ResourcePayload;
68 use stackless_core::def::StackDef;
69 use stackless_stripe_projects::stripe::StripeProjects;
70 use stackless_stripe_projects::test_support;
71
72 #[test]
73 fn config_matches_catalog() {
74 const FIXTURE: &str = include_str!(concat!(
75 env!("CARGO_MANIFEST_DIR"),
76 "/../stackless-stripe-projects/tests/fixtures/catalog.json"
77 ));
78 let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
79 let failures =
80 stackless_stripe_projects::verify_service(&catalog, &RailwayHostingConfig {});
81 assert!(
82 failures.is_empty(),
83 "railway/hosting catalog gaps:\n{}",
84 failures.join("\n")
85 );
86 }
87
88 const CATALOG_ENVELOPE: &str = r##"{"ok":true,"command":"projects catalog","data":{"last_updated":"2026-07-11T00:00:00Z","services":[{"id":"prvsvc_hosting","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_railway","provider_name":"Railway","service_id":"hosting","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"component"},"configuration_schema":{"properties":{},"type":"object"}}]}}"##;
89
90 fn test_def() -> StackDef {
91 StackDef::parse(
92 r#"
93[stack]
94name = "atto"
95[stack.projects.stripe]
96project = "project_1"
97[integrations.res]
98provider = "railway-hosting"
99[services.api]
100source = { repo = "r", ref = "main" }
101env = { OUT = "${integrations.res.url}" }
102health = { path = "/health" }
103[services.api.local]
104run = "true"
105"#,
106 )
107 .unwrap()
108 }
109
110 #[tokio::test]
111 async fn provision_records_outputs() {
112 let runner = test_support::provision_script(
113 CATALOG_ENVELOPE,
114 serde_json::json!({
115 "RAILWAY_URL": "https://example.up.railway.app",
116 "RAILWAY_DOMAIN": "example.up.railway.app",
117 "RAILWAY_DASHBOARD_URL": "https://railway.app/project/1",
118 "RAILWAY_TYPE": "service"
119 }),
120 0,
121 );
122 let dir = tempfile::tempdir().unwrap();
123 std::fs::write(
124 dir.path().join("stackless.toml"),
125 "[stack]\nname=\"atto\"\n",
126 )
127 .unwrap();
128 let stripe = StripeProjects::new(&runner, dir.path());
129
130 let resource = RailwayHosting
131 .provision(
132 &stripe.as_dyn(),
133 &test_def(),
134 dir.path(),
135 "demo",
136 "res",
137 "local",
138 false,
139 )
140 .await
141 .unwrap();
142 assert_eq!(resource.resource_kind, "integration-railway-hosting");
143 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
144 assert_eq!(payload.outputs["url"], "https://example.up.railway.app");
145 }
146}