stackless_integrations/providers/upstash/
qstash.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-upstash-qstash";
14
15#[derive(Debug, Serialize)]
16pub struct UpstashQstashConfig {
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub price: Option<String>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub region: Option<String>,
21}
22
23impl CatalogService for UpstashQstashConfig {
24 const REFERENCE: &'static str = "upstash/qstash";
25}
26
27#[derive(Debug)]
28pub struct UpstashQstash;
29
30impl Hostable for UpstashQstash {
31 const PROVIDER: &'static str = "upstash-qstash";
32 const HOSTING: IntegrationHosting = IntegrationHosting::Managed;
33 const CONFIG_SCOPE: ConfigScope = ConfigScope::GlobalOnly;
34 const RESOURCE_KIND: &'static str = RESOURCE_KIND;
35 const OUTPUTS: &'static [&'static str] = &["token", "qstash_id"];
36}
37
38impl FamilyResource for UpstashQstash {
39 type Config = UpstashQstashConfig;
40 const PROVIDER_PREFIX: &'static str = "UPSTASH";
41 const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] =
42 &[("TOKEN", "token", true), ("QSTASH_ID", "qstash_id", false)];
43
44 fn build_config(ctx: &ProvisionContext<'_>) -> Result<UpstashQstashConfig, IntegrationError> {
45 let config = super::integration_config(ctx)?;
46 Ok(UpstashQstashConfig {
47 price: super::interp_optional(ctx, &config, "price")?,
48 region: super::interp_optional(ctx, &config, "region")?,
49 })
50 }
51}
52
53pub fn validate_config(
54 name: &str,
55 config: &BTreeMap<String, toml::Value>,
56) -> Result<(), IntegrationError> {
57 let _ = (name, config);
58 Ok(())
59}
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64 use crate::ProviderOps;
65 use crate::resource::ResourcePayload;
66 use stackless_core::def::StackDef;
67 use stackless_stripe_projects::stripe::StripeProjects;
68 use stackless_stripe_projects::test_support;
69
70 #[test]
71 fn config_matches_catalog() {
72 const FIXTURE: &str = include_str!(concat!(
73 env!("CARGO_MANIFEST_DIR"),
74 "/../stackless-stripe-projects/tests/fixtures/catalog.json"
75 ));
76 let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
77 let failures = stackless_stripe_projects::verify_service(
78 &catalog,
79 &UpstashQstashConfig {
80 price: None,
81 region: None,
82 },
83 );
84 assert!(
85 failures.is_empty(),
86 "upstash/qstash catalog gaps:\n{}",
87 failures.join("\n")
88 );
89 }
90
91 const CATALOG_ENVELOPE: &str = r##"{"ok":true,"command":"projects catalog","data":{"last_updated":"2026-07-11T00:00:00Z","services":[{"id":"prvsvc_qstash","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_upstash","provider_name":"Upstash","service_id":"qstash","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"paid"},"configuration_schema":{"properties":{"price":{"default":"payg","description":"Pricing tier. 'free' provisions on the free plan (subject to free-tier limits and one-per-account). 'payg' provisions pay-as-you-go. Defaults to 'payg'.","enum":["free","payg"],"type":"string"},"region":{"description":"Region for the QStash user","enum":["eu-central-1","us-east-1"],"type":"string"}},"type":"object"}}]}}"##;
92
93 fn test_def() -> StackDef {
94 StackDef::parse(
95 r#"
96[stack]
97name = "atto"
98[stack.projects.stripe]
99project = "project_1"
100[integrations.res]
101provider = "upstash-qstash"
102[services.api]
103source = { repo = "r", ref = "main" }
104env = { OUT = "${integrations.res.token}" }
105health = { path = "/health" }
106[services.api.local]
107run = "true"
108"#,
109 )
110 .unwrap()
111 }
112
113 #[tokio::test]
114 async fn provision_records_outputs() {
115 let runner = test_support::provision_script(
116 CATALOG_ENVELOPE,
117 serde_json::json!({"UPSTASH_TOKEN": "val_token", "UPSTASH_QSTASH_ID": "val_qstash_id"}),
118 0,
119 );
120 let dir = tempfile::tempdir().unwrap();
121 std::fs::write(
122 dir.path().join("stackless.toml"),
123 "[stack]\nname=\"atto\"\n",
124 )
125 .unwrap();
126 let stripe = StripeProjects::new(&runner, dir.path());
127
128 let resource = UpstashQstash
129 .provision(
130 &stripe.as_dyn(),
131 &test_def(),
132 dir.path(),
133 "demo",
134 "res",
135 "local",
136 false,
137 )
138 .await
139 .unwrap();
140 assert_eq!(resource.resource_kind, "integration-upstash-qstash");
141 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
142 assert_eq!(payload.outputs["token"], "val_token");
143 }
144}