mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
Merge branch 'integration/new-container-runtime' of github.com:Start9Labs/start-os into integration/new-container-runtime
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::{borrow::Borrow, collections::BTreeMap};
|
||||
|
||||
use clap::Parser;
|
||||
use imbl_value::{json, InOMap, InternedString, Value};
|
||||
@@ -15,48 +15,6 @@ pub fn display_properties(response: Value) {
|
||||
println!("{}", response);
|
||||
}
|
||||
|
||||
trait IntoProperties {
|
||||
fn into_properties(self, store: &Value) -> Value;
|
||||
}
|
||||
impl IntoProperties for ExposedUI {
|
||||
fn into_properties(self, store: &Value) -> Value {
|
||||
match self {
|
||||
ExposedUI::Object { value, description } => {
|
||||
json!({
|
||||
"type": "object",
|
||||
"description": description,
|
||||
"value": value.into_iter().map(|(k, v)| (k, v.into_properties(store))).collect::<BTreeMap<String,_>>()
|
||||
})
|
||||
}
|
||||
ExposedUI::String {
|
||||
path,
|
||||
description,
|
||||
masked,
|
||||
copyable,
|
||||
qr,
|
||||
} => json!({
|
||||
"type": "string",
|
||||
"description": description,
|
||||
"value": path.get(store).cloned().unwrap_or_default(),
|
||||
"copyable": copyable,
|
||||
"qr": qr,
|
||||
"masked": masked
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoProperties for StoreExposedUI {
|
||||
fn into_properties(self, store: &Value) -> Value {
|
||||
Value::Object(
|
||||
self.0
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, v.into_properties(store)))
|
||||
.collect::<InOMap<InternedString, Value>>(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Parser)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[command(rename_all = "kebab-case")]
|
||||
@@ -68,19 +26,11 @@ pub async fn properties(
|
||||
ctx: RpcContext,
|
||||
PropertiesParam { id }: PropertiesParam,
|
||||
) -> Result<Value, Error> {
|
||||
let peeked = ctx.db.peek().await;
|
||||
let data = peeked
|
||||
.as_private()
|
||||
.as_package_stores()
|
||||
.as_idx(&id)
|
||||
.map(|x| x.de())
|
||||
.unwrap_or_else(|| Ok(json!({})))?;
|
||||
Ok(peeked
|
||||
.as_public()
|
||||
.as_package_data()
|
||||
.as_idx(&id)
|
||||
.or_not_found(&id)?
|
||||
.as_store_exposed_ui()
|
||||
.de()?
|
||||
.into_properties(&data))
|
||||
match &*ctx.services.get(&id).await {
|
||||
Some(service) => service.properties().await,
|
||||
None => Err(Error::new(
|
||||
eyre!("Could not find a service with id {id}"),
|
||||
ErrorKind::NotFound,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,6 +325,17 @@ impl Service {
|
||||
.await
|
||||
.with_kind(ErrorKind::Action)
|
||||
}
|
||||
pub async fn properties(&self) -> Result<Value, Error> {
|
||||
let container = &self.seed.persistent_container;
|
||||
container
|
||||
.execute::<Value>(
|
||||
ProcedureName::Properties,
|
||||
Value::Null,
|
||||
Some(Duration::from_secs(30)),
|
||||
)
|
||||
.await
|
||||
.with_kind(ErrorKind::Unknown)
|
||||
}
|
||||
|
||||
pub async fn shutdown(self) -> Result<(), Error> {
|
||||
self.actor
|
||||
|
||||
Reference in New Issue
Block a user