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