fluentci_graphql/schema/objects/
secret.rs1use std::sync::{Arc, Mutex};
2
3use async_graphql::{Context, Error, Object, ID};
4use fluentci_core::deps::Graph;
5use fluentci_types::secret as types;
6
7#[derive(Debug, Clone, Default)]
8pub struct Secret {
9 pub id: ID,
10 pub name: String,
11 pub mount: String,
12}
13
14impl From<types::Secret> for Secret {
15 fn from(secret: types::Secret) -> Self {
16 Self {
17 id: secret.id.into(),
18 name: secret.name,
19 mount: secret.mount,
20 }
21 }
22}
23
24#[Object]
25impl Secret {
26 async fn id(&self) -> &ID {
27 &self.id
28 }
29
30 async fn plaintext(&self, ctx: &Context<'_>) -> Result<String, Error> {
31 let graph = ctx.data::<Arc<Mutex<Graph>>>().unwrap();
32 let graph = graph.lock().unwrap();
33 let value = graph.get_secret_plaintext(self.id.to_string().clone(), self.name.clone())?;
34 Ok(value)
35 }
36
37 async fn name(&self) -> &str {
38 &self.name
39 }
40
41 async fn mount(&self) -> &str {
42 &self.mount
43 }
44}