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