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] = &["auth_token", "dsn", "org", "project", "url"];
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)] = &[
42 ("AUTH_TOKEN", "auth_token", true),
43 ("DSN", "dsn", true),
44 ("ORG", "org", true),
45 ("PROJECT", "project", true),
46 ("URL", "url", true),
47 ];
48
49 fn build_config(ctx: &ProvisionContext<'_>) -> Result<SentryProjectConfig, IntegrationError> {
50 let config = super::integration_config(ctx)?;
51 Ok(SentryProjectConfig {
52 platform: super::interp_optional(ctx, &config, "platform")?,
53 project_name: super::interp_optional(ctx, &config, "project_name")?,
54 })
55 }
56}
57
58pub fn validate_config(
59 name: &str,
60 config: &BTreeMap<String, toml::Value>,
61) -> Result<(), IntegrationError> {
62 let _ = (name, config);
63 Ok(())
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69 use crate::ProviderOps;
70 use crate::resource::ResourcePayload;
71 use stackless_core::def::StackDef;
72 use stackless_stripe_projects::stripe::StripeProjects;
73 use stackless_stripe_projects::test_support;
74
75 #[test]
76 fn config_matches_catalog() {
77 const FIXTURE: &str = include_str!(concat!(
78 env!("CARGO_MANIFEST_DIR"),
79 "/../stackless-stripe-projects/tests/fixtures/catalog.json"
80 ));
81 let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
82 let failures = stackless_stripe_projects::verify_service(
83 &catalog,
84 &SentryProjectConfig {
85 platform: None,
86 project_name: None,
87 },
88 );
89 assert!(
90 failures.is_empty(),
91 "sentry/project catalog gaps:\n{}",
92 failures.join("\n")
93 );
94 }
95
96 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"}}]}}"##;
97
98 fn test_def() -> StackDef {
99 StackDef::parse(
100 r#"
101[stack]
102name = "atto"
103[stack.projects.stripe]
104project = "project_1"
105[integrations.res]
106provider = "sentry"
107[services.api]
108source = { repo = "r", ref = "main" }
109env = { OUT = "${integrations.res.dsn}" }
110health = { path = "/health" }
111[services.api.local]
112run = "true"
113"#,
114 )
115 .unwrap()
116 }
117
118 #[tokio::test]
119 async fn provision_records_outputs() {
120 let runner = test_support::provision_script(
121 CATALOG_ENVELOPE,
122 serde_json::json!({"SENTRY_AUTH_TOKEN": "val_auth_token", "SENTRY_DSN": "val_dsn", "SENTRY_ORG": "val_org", "SENTRY_PROJECT": "val_project", "SENTRY_URL": "val_url"}),
123 0,
124 );
125 let dir = tempfile::tempdir().unwrap();
126 std::fs::write(
127 dir.path().join("stackless.toml"),
128 "[stack]\nname=\"atto\"\n",
129 )
130 .unwrap();
131 let stripe = StripeProjects::new(&runner, dir.path());
132
133 let resource = SentryProject
134 .provision(
135 &stripe.as_dyn(),
136 &test_def(),
137 dir.path(),
138 "demo",
139 "res",
140 "local",
141 false,
142 )
143 .await
144 .unwrap();
145 assert_eq!(resource.resource_kind, "integration-sentry");
146 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
147 assert_eq!(payload.outputs["auth_token"], "val_auth_token");
148 assert_eq!(payload.outputs["dsn"], "val_dsn");
149 assert_eq!(payload.outputs["org"], "val_org");
150 assert_eq!(payload.outputs["project"], "val_project");
151 assert_eq!(payload.outputs["url"], "val_url");
152 }
153}