mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
* Feat: js action wip: Getting async js feat: Have execute get action config feat: Read + Write chore: Add typing for globals chore: Change the default path, include error on missing function, and add json File Read Write chore: Change the default path, include error on missing function, and add json File Read Write wip: Fix the unit test wip: Fix the unit test feat: module loading * fix: Change the source + add input * fix: single thread runtime * fix: Smaller fixes * Apply suggestions from code review Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> * fix: pr Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>
52 lines
1.5 KiB
Rust
52 lines
1.5 KiB
Rust
use clap::ArgMatches;
|
|
use color_eyre::eyre::eyre;
|
|
use rpc_toolkit::command;
|
|
use serde_json::Value;
|
|
use tracing::instrument;
|
|
|
|
use crate::context::RpcContext;
|
|
use crate::procedure::ProcedureName;
|
|
use crate::s9pk::manifest::{Manifest, PackageId};
|
|
use crate::{Error, ErrorKind};
|
|
|
|
pub fn display_properties(response: Value, _: &ArgMatches<'_>) {
|
|
println!("{}", response);
|
|
}
|
|
|
|
#[command(display(display_properties))]
|
|
pub async fn properties(#[context] ctx: RpcContext, #[arg] id: PackageId) -> Result<Value, Error> {
|
|
Ok(fetch_properties(ctx, id).await?)
|
|
}
|
|
|
|
#[instrument(skip(ctx))]
|
|
pub async fn fetch_properties(ctx: RpcContext, id: PackageId) -> Result<Value, Error> {
|
|
let mut db = ctx.db.handle();
|
|
let manifest: Manifest = crate::db::DatabaseModel::new()
|
|
.package_data()
|
|
.idx_model(&id)
|
|
.and_then(|p| p.installed())
|
|
.map(|m| m.manifest())
|
|
.get(&mut db, true)
|
|
.await?
|
|
.to_owned()
|
|
.ok_or_else(|| Error::new(eyre!("{} is not installed", id), ErrorKind::NotFound))?;
|
|
if let Some(props) = manifest.properties {
|
|
props
|
|
.execute::<(), Value>(
|
|
&ctx,
|
|
&manifest.id,
|
|
&manifest.version,
|
|
ProcedureName::Properties,
|
|
&manifest.volumes,
|
|
None,
|
|
false,
|
|
None,
|
|
)
|
|
.await?
|
|
.map_err(|(_, e)| Error::new(eyre!("{}", e), ErrorKind::Docker))
|
|
.and_then(|a| Ok(a))
|
|
} else {
|
|
Ok(Value::Null)
|
|
}
|
|
}
|