stackless_integrations/providers/sentry/
project.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-sentry";
14
15#[derive(Debug, Serialize)]
16pub struct SentryProjectConfig {
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub platform: Option<String>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub project_name: Option<String>,
21}
22
23impl CatalogService for SentryProjectConfig {
24 const REFERENCE: &'static str = "sentry/project";
25}
26
27#[derive(Debug)]
28pub struct SentryProject;
29
30impl Hostable for SentryProject {
31 const PROVIDER: &'static str = "sentry";
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] = &["dsn"];
36}
37
38impl FamilyResource for SentryProject {
39 type Config = SentryProjectConfig;
40 const PROVIDER_PREFIX: &'static str = "SENTRY";
41 const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] = &[("DSN", "dsn", true)];
43
44 fn build_config(ctx: &ProvisionContext<'_>) -> Result<SentryProjectConfig, IntegrationError> {
45 let config = super::integration_config(ctx)?;
46 Ok(SentryProjectConfig {
47 platform: super::interp_optional(ctx, &config, "platform")?,
48 project_name: super::interp_optional(ctx, &config, "project_name")?,
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 &SentryProjectConfig {
80 platform: None,
81 project_name: None,
82 },
83 );
84 assert!(
85 failures.is_empty(),
86 "sentry/project 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_project","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_sentry","provider_name":"Sentry","service_id":"project","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"component"},"configuration_schema":{"properties":{"platform":{"description":"Platform/language (e.g. python, javascript, node, react)","type":"string"},"project_name":{"description":"Name for the Sentry project","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 = "sentry"
102[services.api]
103source = { repo = "r", ref = "main" }
104env = { OUT = "${integrations.res.dsn}" }
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!({"SENTRY_DSN": "val_dsn"}),
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 = SentryProject
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-sentry");
141 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
142 assert_eq!(payload.outputs["dsn"], "val_dsn");
143 }
144}