Merge branch 'integration/new-container-runtime' of github.com:Start9Labs/start-os into integration/new-container-runtime

This commit is contained in:
Aiden McClelland
2024-03-25 15:47:24 -06:00
13 changed files with 131 additions and 439 deletions

View File

@@ -9,6 +9,7 @@ pub enum ProcedureName {
GetConfig,
SetConfig,
CreateBackup,
Properties,
RestoreBackup,
ActionMetadata,
RunAction(ActionId),
@@ -29,6 +30,7 @@ impl ProcedureName {
ProcedureName::SetConfig => "/config/set".to_string(),
ProcedureName::GetConfig => "/config/get".to_string(),
ProcedureName::CreateBackup => "/backup/create".to_string(),
ProcedureName::Properties => "/properties".to_string(),
ProcedureName::RestoreBackup => "/backup/restore".to_string(),
ProcedureName::ActionMetadata => "/actions/metadata".to_string(),
ProcedureName::RunAction(id) => format!("/actions/{}/run", id),

View File

@@ -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,
)),
}
}

View File

@@ -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