stackless_integrations/providers/laravel_cloud/
valkey.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-valkey";
15
16#[derive(Debug, Serialize)]
17pub struct LaravelCloudValkeyConfig {
18 pub instance_size: String,
19 pub region: String,
20}
21
22impl CatalogService for LaravelCloudValkeyConfig {
23 const REFERENCE: &'static str = "laravel_cloud/valkey";
24}
25
26#[derive(Debug)]
27pub struct LaravelCloudValkey;
28
29impl Hostable for LaravelCloudValkey {
30 const PROVIDER: &'static str = "laravel-cloud-valkey";
31 const HOSTING: IntegrationHosting = IntegrationHosting::Managed;
32 const CONFIG_SCOPE: ConfigScope = ConfigScope::GlobalOnly;
33 const RESOURCE_KIND: &'static str = RESOURCE_KIND;
34 const OUTPUTS: &'static [&'static str] = &["redis_url"];
35}
36
37impl FamilyResource for LaravelCloudValkey {
38 type Config = LaravelCloudValkeyConfig;
39 const PROVIDER_PREFIX: &'static str = "LARAVEL_CLOUD";
40 const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] =
42 &[("REDIS_URL", "redis_url", true)];
43
44 fn build_config(
45 ctx: &ProvisionContext<'_>,
46 ) -> Result<LaravelCloudValkeyConfig, IntegrationError> {
47 let config = super::integration_config(ctx)?;
48 Ok(LaravelCloudValkeyConfig {
49 instance_size: super::interp_required(ctx, &config, "instance_size")?,
50 region: super::interp_required(ctx, &config, "region")?,
51 })
52 }
53}
54
55pub fn validate_config(
56 name: &str,
57 config: &BTreeMap<String, toml::Value>,
58) -> Result<(), IntegrationError> {
59 registry::config_string(config, "instance_size").map_err(|err| {
60 IntegrationError::ConfigInvalid {
61 location: format!("integrations.{name}.instance_size"),
62 detail: err.to_string(),
63 }
64 })?;
65 registry::config_string(config, "region").map_err(|err| IntegrationError::ConfigInvalid {
66 location: format!("integrations.{name}.region"),
67 detail: err.to_string(),
68 })?;
69 let _ = (name, config);
70 Ok(())
71}
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76 use crate::ProviderOps;
77 use crate::resource::ResourcePayload;
78 use stackless_core::def::StackDef;
79 use stackless_stripe_projects::stripe::StripeProjects;
80 use stackless_stripe_projects::test_support;
81
82 #[test]
83 fn config_matches_catalog() {
84 const FIXTURE: &str = include_str!(concat!(
85 env!("CARGO_MANIFEST_DIR"),
86 "/../stackless-stripe-projects/tests/fixtures/catalog.json"
87 ));
88 let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
89 let failures = stackless_stripe_projects::verify_service(
90 &catalog,
91 &LaravelCloudValkeyConfig {
92 instance_size: "valkey-flex-250mb".into(),
93 region: "us-east-1".into(),
94 },
95 );
96 assert!(
97 failures.is_empty(),
98 "laravel_cloud/valkey catalog gaps:\n{}",
99 failures.join("\n")
100 );
101 }
102
103 const CATALOG_ENVELOPE: &str = r##"{"ok":true,"command":"projects catalog","data":{"last_updated":"2026-07-11T00:00:00Z","services":[{"id":"prvsvc_valkey","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_laravel_cloud","provider_name":"Laravel_Cloud","service_id":"valkey","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"component"},"configuration_schema":{"properties":{"instance_size":{"enum":["valkey-flex-250mb","valkey-flex-1gb","valkey-flex-2.5gb","valkey-pro.5gb","valkey-pro.12gb","valkey-pro.25gb","valkey-pro.50gb"],"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"}},"required":["instance_size","region"],"type":"object"}}]}}"##;
104
105 fn test_def() -> StackDef {
106 StackDef::parse(
107 r#"
108[stack]
109name = "atto"
110[stack.projects.stripe]
111project = "project_1"
112[integrations.res]
113provider = "laravel-cloud-valkey"
114instance_size = "valkey-flex-250mb"
115region = "us-east-1"
116[services.api]
117source = { repo = "r", ref = "main" }
118env = { OUT = "${integrations.res.redis_url}" }
119health = { path = "/health" }
120[services.api.local]
121run = "true"
122"#,
123 )
124 .unwrap()
125 }
126
127 #[tokio::test]
128 async fn provision_records_outputs() {
129 let runner = test_support::provision_script(
130 CATALOG_ENVELOPE,
131 serde_json::json!({"LARAVEL_CLOUD_REDIS_URL": "val_redis_url"}),
132 0,
133 );
134 let dir = tempfile::tempdir().unwrap();
135 std::fs::write(
136 dir.path().join("stackless.toml"),
137 "[stack]\nname=\"atto\"\n",
138 )
139 .unwrap();
140 let stripe = StripeProjects::new(&runner, dir.path());
141
142 let resource = LaravelCloudValkey
143 .provision(
144 &stripe.as_dyn(),
145 &test_def(),
146 dir.path(),
147 "demo",
148 "res",
149 "local",
150 false,
151 )
152 .await
153 .unwrap();
154 assert_eq!(resource.resource_kind, "integration-laravel-cloud-valkey");
155 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
156 assert_eq!(payload.outputs["redis_url"], "val_redis_url");
157 }
158}