stackless_integrations/providers/neon/
postgres.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-neon";
14
15#[derive(Debug, Serialize)]
16pub struct NeonPostgresConfig {}
17
18impl CatalogService for NeonPostgresConfig {
19 const REFERENCE: &'static str = "neon/postgres";
20}
21
22#[derive(Debug)]
23pub struct NeonPostgres;
24
25impl Hostable for NeonPostgres {
26 const PROVIDER: &'static str = "neon";
27 const HOSTING: IntegrationHosting = IntegrationHosting::Managed;
28 const CONFIG_SCOPE: ConfigScope = ConfigScope::GlobalOnly;
29 const RESOURCE_KIND: &'static str = RESOURCE_KIND;
30 const OUTPUTS: &'static [&'static str] = &["database_url", "host"];
31}
32
33impl FamilyResource for NeonPostgres {
34 type Config = NeonPostgresConfig;
35 const PROVIDER_PREFIX: &'static str = "NEON";
36 const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] = &[
38 ("DATABASE_URL", "database_url", true),
39 ("HOST", "host", false),
40 ];
41
42 fn build_config(ctx: &ProvisionContext<'_>) -> Result<NeonPostgresConfig, IntegrationError> {
43 let _ = super::integration_config(ctx)?;
44 Ok(NeonPostgresConfig {})
45 }
46}
47
48pub fn validate_config(
49 name: &str,
50 config: &BTreeMap<String, toml::Value>,
51) -> Result<(), IntegrationError> {
52 let _ = (name, config);
53 Ok(())
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59 use crate::ProviderOps;
60 use crate::resource::ResourcePayload;
61 use stackless_core::def::StackDef;
62 use stackless_stripe_projects::stripe::StripeProjects;
63 use stackless_stripe_projects::test_support;
64
65 #[test]
66 fn config_matches_catalog() {
67 const FIXTURE: &str = include_str!(concat!(
68 env!("CARGO_MANIFEST_DIR"),
69 "/../stackless-stripe-projects/tests/fixtures/catalog.json"
70 ));
71 let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
72 let failures = stackless_stripe_projects::verify_service(&catalog, &NeonPostgresConfig {});
73 assert!(
74 failures.is_empty(),
75 "neon/postgres catalog gaps:\n{}",
76 failures.join("\n")
77 );
78 }
79
80 const CATALOG_ENVELOPE: &str = r##"{"ok":true,"command":"projects catalog","data":{"last_updated":"2026-07-11T00:00:00Z","services":[{"id":"prvsvc_postgres","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_neon","provider_name":"Neon","service_id":"postgres","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"component"},"configuration_schema":{"type":"object","required":[],"additionalProperties":false,"properties":{}}}]}}"##;
81
82 fn test_def() -> StackDef {
83 StackDef::parse(
84 r#"
85[stack]
86name = "atto"
87[stack.projects.stripe]
88project = "project_1"
89[integrations.res]
90provider = "neon"
91[services.api]
92source = { repo = "r", ref = "main" }
93env = { OUT = "${integrations.res.database_url}" }
94health = { path = "/health" }
95[services.api.local]
96run = "true"
97"#,
98 )
99 .unwrap()
100 }
101
102 #[tokio::test]
103 async fn provision_records_outputs() {
104 let runner = test_support::provision_script(
105 CATALOG_ENVELOPE,
106 serde_json::json!({"NEON_DATABASE_URL": "val_database_url", "NEON_HOST": "val_host"}),
107 0,
108 );
109 let dir = tempfile::tempdir().unwrap();
110 std::fs::write(
111 dir.path().join("stackless.toml"),
112 "[stack]\nname=\"atto\"\n",
113 )
114 .unwrap();
115 let stripe = StripeProjects::new(&runner, dir.path());
116
117 let resource = NeonPostgres
118 .provision(
119 &stripe.as_dyn(),
120 &test_def(),
121 dir.path(),
122 "demo",
123 "res",
124 "local",
125 false,
126 )
127 .await
128 .unwrap();
129 assert_eq!(resource.resource_kind, "integration-neon");
130 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
131 assert_eq!(payload.outputs["database_url"], "val_database_url");
132 }
133}