stackless_integrations/providers/parallel/
api.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-parallel";
14
15#[derive(Debug, Serialize)]
16pub struct ParallelApiConfig {
17 pub product: String,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub processor: Option<String>,
23 #[serde(skip_serializing_if = "Option::is_none")]
24 pub generator: Option<String>,
25 #[serde(skip_serializing_if = "Option::is_none")]
26 pub tier: Option<String>,
27}
28
29impl CatalogService for ParallelApiConfig {
30 const REFERENCE: &'static str = "parallel/api";
31}
32
33#[derive(Debug)]
34pub struct ParallelApi;
35
36impl Hostable for ParallelApi {
37 const PROVIDER: &'static str = "parallel";
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] = &["api_key"];
42}
43
44impl FamilyResource for ParallelApi {
45 type Config = ParallelApiConfig;
46 const PROVIDER_PREFIX: &'static str = "PARALLEL";
47 const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] =
49 &[("API_KEY", "api_key", true)];
50
51 fn build_config(ctx: &ProvisionContext<'_>) -> Result<ParallelApiConfig, IntegrationError> {
52 let config = super::integration_config(ctx)?;
53 Ok(ParallelApiConfig {
54 product: super::interp_optional(ctx, &config, "product")?
55 .unwrap_or_else(|| "search".to_owned()),
56 processor: super::interp_optional(ctx, &config, "processor")?,
57 generator: super::interp_optional(ctx, &config, "generator")?,
58 tier: super::interp_optional(ctx, &config, "tier")?,
59 })
60 }
61}
62
63pub fn validate_config(
64 name: &str,
65 config: &BTreeMap<String, toml::Value>,
66) -> Result<(), IntegrationError> {
67 let _ = (name, config);
68 Ok(())
69}
70
71#[cfg(test)]
72mod tests {
73 use super::*;
74 use crate::ProviderOps;
75 use crate::resource::ResourcePayload;
76 use stackless_core::def::StackDef;
77 use stackless_stripe_projects::stripe::StripeProjects;
78 use stackless_stripe_projects::test_support;
79
80 #[test]
81 fn config_matches_catalog() {
82 const FIXTURE: &str = include_str!(concat!(
83 env!("CARGO_MANIFEST_DIR"),
84 "/../stackless-stripe-projects/tests/fixtures/catalog.json"
85 ));
86 let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
87 let failures = stackless_stripe_projects::verify_service(
88 &catalog,
89 &ParallelApiConfig {
90 product: "search".into(),
91 processor: None,
92 generator: None,
93 tier: None,
94 },
95 );
96 assert!(
97 failures.is_empty(),
98 "parallel/api 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_api","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_parallel","provider_name":"Parallel","service_id":"api","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"paid","paid_pricing":[{"type":"freeform","is_default":true,"configuration":{"product":"search"}}]},"configuration_schema":{"type":"object","required":[],"additionalProperties":false,"properties":{}}}]}}"##;
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 = "parallel"
114[services.api]
115source = { repo = "r", ref = "main" }
116env = { OUT = "${integrations.res.api_key}" }
117health = { path = "/health" }
118[services.api.local]
119run = "true"
120"#,
121 )
122 .unwrap()
123 }
124
125 #[tokio::test]
126 async fn provision_records_outputs() {
127 let runner = test_support::provision_script(
128 CATALOG_ENVELOPE,
129 serde_json::json!({"PARALLEL_API_KEY": "val_api_key"}),
130 0,
131 );
132 let dir = tempfile::tempdir().unwrap();
133 std::fs::write(
134 dir.path().join("stackless.toml"),
135 "[stack]\nname=\"atto\"\n",
136 )
137 .unwrap();
138 let stripe = StripeProjects::new(&runner, dir.path());
139
140 let resource = ParallelApi
141 .provision(
142 &stripe.as_dyn(),
143 &test_def(),
144 dir.path(),
145 "demo",
146 "res",
147 "local",
148 false,
149 )
150 .await
151 .unwrap();
152 assert_eq!(resource.resource_kind, "integration-parallel");
153 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
154 assert_eq!(payload.outputs["api_key"], "val_api_key");
155 }
156}