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