siera_cloudagent_python/cloudagent/
schema.rs1use crate::agent::CloudAgentPython;
2use async_trait::async_trait;
3use serde::{Deserialize, Serialize};
4use serde_json::json;
5use siera_agent::error::Result;
6use siera_agent::modules::schema::{
7 Schema, SchemaCreateOptions, SchemaModule, SchemasGetAllResponse,
8};
9
10#[derive(Serialize, Deserialize, Debug)]
12struct Response {
13 schema: Schema,
15}
16
17#[async_trait]
18impl SchemaModule for CloudAgentPython {
19 async fn create(&self, options: SchemaCreateOptions) -> Result<Schema> {
20 let url = self.create_url(&["schemas"])?;
21
22 let body = json!({
23 "attributes": options.attributes,
24 "schema_name": options.name,
25 "schema_version": options.version
26 });
27
28 Ok(self.post::<Response>(url, None, Some(body)).await?.schema)
29 }
30
31 async fn get_by_id(&self, id: String) -> Result<Schema> {
32 let url = self.create_url(&["schemas", &id])?;
33 Ok(self.get::<Response>(url, None).await?.schema)
34 }
35
36 async fn get_all(&self) -> Result<SchemasGetAllResponse> {
37 let url = self.create_url(&["schemas", "created"])?;
38 self.get(url, None).await
39 }
40}