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