mercury_cli/
specification.rs

1use anyhow::Result;
2use serde::{Deserialize, Serialize};
3
4use crate::{MercuryClient, ZephyrProjectParser};
5
6#[derive(Deserialize, Serialize, Clone)]
7pub struct Index {
8    pub name: String,
9    pub title: String,
10    pub description: Option<String>,
11    pub instructions: Option<String>,
12    pub tags: Vec<String>,
13}
14
15#[derive(Deserialize, Serialize, Clone)]
16pub struct Dashboard {
17    pub title: String,
18    pub description: Option<String>,
19    pub tags: Vec<String>,
20}
21
22impl ZephyrProjectParser {
23    pub async fn register_indexes(&self) -> Result<()> {
24        if let Some(indexes) = self.config.indexes.clone() {
25            for index in indexes {
26                let client = reqwest::Client::new();
27                client
28                    .put(format!("{}/api/indexes", self.client.base_url))
29                    .header("Authorization", self.client.get_auth())
30                    //.bearer_auth(self.client.jwt.clone())
31                    .header("Content-Type", "application/json")
32                    .body(serde_json::to_string(&index)?)
33                    .send()
34                    .await?;
35            }
36        }
37
38        Ok(())
39    }
40
41    pub async fn register_dashboard(&self) -> Result<()> {
42        if let Some(dashboard) = self.config.dashboard.clone() {
43            let client = reqwest::Client::new();
44            client
45                .put(format!("{}/api/dashboard", self.client.base_url))
46                .header("Authorization", self.client.get_auth())
47                //.bearer_auth(self.client.jwt.clone())
48                .header("Content-Type", "application/json")
49                .body(serde_json::to_string(&dashboard)?)
50                .send()
51                .await?;
52        }
53
54        Ok(())
55    }
56}