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] = &["host", "password", "port"];
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)] = &[
41 ("HOST", "host", false),
42 ("PASSWORD", "password", true),
43 ("PORT", "port", true),
44 ];
45
46 fn build_config(
47 ctx: &ProvisionContext<'_>,
48 ) -> Result<LaravelCloudValkeyConfig, IntegrationError> {
49 let config = super::integration_config(ctx)?;
50 Ok(LaravelCloudValkeyConfig {
51 instance_size: super::interp_required(ctx, &config, "instance_size")?,
52 region: super::interp_required(ctx, &config, "region")?,
53 })
54 }
55}
56
57pub fn validate_config(
58 name: &str,
59 config: &BTreeMap<String, toml::Value>,
60) -> Result<(), IntegrationError> {
61 registry::config_string(config, "instance_size").map_err(|err| {
62 IntegrationError::ConfigInvalid {
63 location: format!("integrations.{name}.instance_size"),
64 detail: err.to_string(),
65 }
66 })?;
67 registry::config_string(config, "region").map_err(|err| IntegrationError::ConfigInvalid {
68 location: format!("integrations.{name}.region"),
69 detail: err.to_string(),
70 })?;
71 let _ = (name, config);
72 Ok(())
73}
74
75#[cfg(test)]
76mod tests {
77 use super::*;
78 use crate::ProviderOps;
79 use crate::resource::ResourcePayload;
80 use stackless_core::def::StackDef;
81 use stackless_stripe_projects::stripe::StripeProjects;
82 use stackless_stripe_projects::test_support;
83
84 #[test]
85 fn config_matches_catalog() {
86 const FIXTURE: &str = include_str!(concat!(
87 env!("CARGO_MANIFEST_DIR"),
88 "/../stackless-stripe-projects/tests/fixtures/catalog.json"
89 ));
90 let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
91 let failures = stackless_stripe_projects::verify_service(
92 &catalog,
93 &LaravelCloudValkeyConfig {
94 instance_size: "valkey-flex-250mb".into(),
95 region: "us-east-1".into(),
96 },
97 );
98 assert!(
99 failures.is_empty(),
100 "laravel_cloud/valkey catalog gaps:\n{}",
101 failures.join("\n")
102 );
103 }
104
105 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"}}]}}"##;
106
107 fn test_def() -> StackDef {
108 StackDef::parse(
109 r#"
110[stack]
111name = "atto"
112[stack.projects.stripe]
113project = "project_1"
114[integrations.res]
115provider = "laravel-cloud-valkey"
116instance_size = "valkey-flex-250mb"
117region = "us-east-1"
118[services.api]
119source = { repo = "r", ref = "main" }
120env = { OUT = "${integrations.res.password}" }
121health = { path = "/health" }
122[services.api.local]
123run = "true"
124"#,
125 )
126 .unwrap()
127 }
128
129 #[tokio::test]
130 async fn provision_records_outputs() {
131 let runner = test_support::provision_script(
132 CATALOG_ENVELOPE,
133 serde_json::json!({"LARAVEL_CLOUD_HOST": "val_host", "LARAVEL_CLOUD_PASSWORD": "val_password", "LARAVEL_CLOUD_PORT": "val_port"}),
134 0,
135 );
136 let dir = tempfile::tempdir().unwrap();
137 std::fs::write(
138 dir.path().join("stackless.toml"),
139 "[stack]\nname=\"atto\"\n",
140 )
141 .unwrap();
142 let stripe = StripeProjects::new(&runner, dir.path());
143
144 let resource = LaravelCloudValkey
145 .provision(
146 &stripe.as_dyn(),
147 &test_def(),
148 dir.path(),
149 "demo",
150 "res",
151 "local",
152 false,
153 )
154 .await
155 .unwrap();
156 assert_eq!(resource.resource_kind, "integration-laravel-cloud-valkey");
157 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
158 assert_eq!(payload.outputs["password"], "val_password");
159 assert_eq!(payload.outputs["port"], "val_port");
160 }
161}