stackless_integrations/providers/laravel_cloud/
application.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};
12use crate::registry;
13
14pub const RESOURCE_KIND: &str = "integration-laravel-cloud";
15
16pub const OUTPUT_FIELDS: &[(&str, &str, bool)] = &[("APP_ID", "app_id", true)];
19
20pub const OUTPUTS: &[&str] = &["app_id"];
21
22#[derive(Debug, Serialize)]
23pub struct LaravelCloudApplicationConfig {
24 pub name: String,
25 pub region: String,
26 pub repository: String,
27 #[serde(skip_serializing_if = "Option::is_none")]
28 pub create_cache: Option<String>,
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub create_database: Option<String>,
31}
32
33impl CatalogService for LaravelCloudApplicationConfig {
34 const REFERENCE: &'static str = "laravel_cloud/application";
35}
36
37#[derive(Debug)]
38pub struct LaravelCloudApplication;
39
40impl Hostable for LaravelCloudApplication {
41 const PROVIDER: &'static str = "laravel-cloud";
42 const HOSTING: IntegrationHosting = IntegrationHosting::Managed;
43 const CONFIG_SCOPE: ConfigScope = ConfigScope::GlobalOnly;
44 const RESOURCE_KIND: &'static str = RESOURCE_KIND;
45 const OUTPUTS: &'static [&'static str] = OUTPUTS;
46}
47
48impl FamilyResource for LaravelCloudApplication {
49 type Config = LaravelCloudApplicationConfig;
50 const PROVIDER_PREFIX: &'static str = "LARAVEL_CLOUD";
51 const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] = OUTPUT_FIELDS;
52
53 fn build_config(
54 ctx: &ProvisionContext<'_>,
55 ) -> Result<LaravelCloudApplicationConfig, IntegrationError> {
56 let config = super::integration_config(ctx)?;
57 Ok(LaravelCloudApplicationConfig {
58 name: super::interp_required(ctx, &config, "name")?,
59 region: super::interp_required(ctx, &config, "region")?,
60 repository: super::interp_required(ctx, &config, "repository")?,
61 create_cache: super::interp_optional(ctx, &config, "create_cache")?,
62 create_database: super::interp_optional(ctx, &config, "create_database")?,
63 })
64 }
65}
66
67pub fn validate_config(
68 name: &str,
69 config: &BTreeMap<String, toml::Value>,
70) -> Result<(), IntegrationError> {
71 registry::config_string(config, "name").map_err(|err| IntegrationError::ConfigInvalid {
72 location: format!("integrations.{name}.name"),
73 detail: err.to_string(),
74 })?;
75 registry::config_string(config, "region").map_err(|err| IntegrationError::ConfigInvalid {
76 location: format!("integrations.{name}.region"),
77 detail: err.to_string(),
78 })?;
79 registry::config_string(config, "repository").map_err(|err| {
80 IntegrationError::ConfigInvalid {
81 location: format!("integrations.{name}.repository"),
82 detail: err.to_string(),
83 }
84 })?;
85 let _ = (name, config);
86 Ok(())
87}
88
89#[cfg(test)]
90mod tests {
91 use super::*;
92 use crate::ProviderOps;
93 use crate::resource::ResourcePayload;
94 use stackless_core::def::StackDef;
95 use stackless_stripe_projects::stripe::StripeProjects;
96 use stackless_stripe_projects::test_support;
97
98 #[test]
99 fn config_matches_catalog() {
100 const FIXTURE: &str = include_str!(concat!(
101 env!("CARGO_MANIFEST_DIR"),
102 "/../stackless-stripe-projects/tests/fixtures/catalog.json"
103 ));
104 let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
105 let failures = stackless_stripe_projects::verify_service(
106 &catalog,
107 &LaravelCloudApplicationConfig {
108 name: "test-name".into(),
109 region: "us-east-1".into(),
110 repository: "test-repository".into(),
111 create_cache: None,
112 create_database: None,
113 },
114 );
115 assert!(
116 failures.is_empty(),
117 "laravel_cloud/application catalog gaps:\n{}",
118 failures.join("\n")
119 );
120 }
121
122 const CATALOG_ENVELOPE: &str = r##"{"ok":true,"command":"projects catalog","data":{"last_updated":"2026-07-11T00:00:00Z","services":[{"id":"prvsvc_application","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_laravel_cloud","provider_name":"Laravel_Cloud","service_id":"application","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"component"},"configuration_schema":{"properties":{"create_cache":{"default":"no","description":"Provision a managed Valkey cache and connect it to this application.","enum":["yes","no"],"title":"Create a cache","type":"string"},"create_database":{"default":"no","description":"Provision a managed MySQL database and connect it to this application.","enum":["yes","no"],"title":"Create a database","type":"string"},"name":{"description":"A name for your Laravel application.","title":"Application Name","type":"string"},"region":{"enum":["us-east-1","us-east-2","eu-central-1","eu-west-1","eu-west-2","ap-southeast-1","ap-southeast-2","ap-northeast-1","ca-central-1","me-central-1"],"type":"string"},"repository":{"description":"Full repository name (e.g. laravel/cloud).","title":"Repository","type":"string"}},"required":["name","repository","region"],"type":"object"}}]}}"##;
123
124 fn test_def() -> StackDef {
125 StackDef::parse(
126 r#"
127[stack]
128name = "atto"
129[stack.projects.stripe]
130project = "project_1"
131[integrations.res]
132provider = "laravel-cloud"
133name = "test-name"
134region = "us-east-1"
135repository = "test-repository"
136[services.api]
137source = { repo = "r", ref = "main" }
138env = { OUT = "${integrations.res.app_id}" }
139health = { path = "/health" }
140[services.api.local]
141run = "true"
142"#,
143 )
144 .unwrap()
145 }
146
147 #[tokio::test]
148 async fn provision_records_outputs() {
149 let runner = test_support::provision_script(
150 CATALOG_ENVELOPE,
151 serde_json::json!({"LARAVEL_CLOUD_APP_ID": "val_app_id"}),
152 0,
153 );
154 let dir = tempfile::tempdir().unwrap();
155 std::fs::write(
156 dir.path().join("stackless.toml"),
157 "[stack]\nname=\"atto\"\n",
158 )
159 .unwrap();
160 let stripe = StripeProjects::new(&runner, dir.path());
161
162 let resource = LaravelCloudApplication
163 .provision(
164 &stripe.as_dyn(),
165 &test_def(),
166 dir.path(),
167 "demo",
168 "res",
169 "local",
170 false,
171 )
172 .await
173 .unwrap();
174 assert_eq!(resource.resource_kind, "integration-laravel-cloud");
175 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
176 assert_eq!(payload.outputs["app_id"], "val_app_id");
177 }
178}