mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
* start consolidating * add start-cli flash-os * combine install and setup and refactor all * use http * undo mock * fix translation * translations * use dialogservice wrapper * better ST messaging on setup * only warn on update if breakages (#3097) * finish setup wizard and ui language-keyboard feature * fix typo * wip: localization * remove start-tunnel readme * switch to posix strings for language internal * revert mock * translate backend strings * fix missing about text * help text for args * feat: add "Add new gateway" option (#3098) * feat: add "Add new gateway" option * Update web/projects/ui/src/app/routes/portal/components/form/controls/select.component.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * add translation --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Matt Hill <mattnine@protonmail.com> * fix dns selection * keyboard keymap also * ability to shutdown after install * revert mock * working setup flow + manifest localization * (mostly) redundant localization on frontend * version bump * omit live medium from disk list and better space management * ignore missing package archive on 035 migration * fix device migration * add i18n helper to sdk * fix install over 0.3.5.1 * fix grub config --------- Co-authored-by: Matt Hill <mattnine@protonmail.com> Co-authored-by: Matt Hill <MattDHill@users.noreply.github.com> Co-authored-by: Alex Inkin <alexander@inkin.ru> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
139 lines
4.0 KiB
Rust
139 lines
4.0 KiB
Rust
use std::collections::BTreeMap;
|
|
|
|
use clap::Parser;
|
|
use exver::Version;
|
|
use rpc_toolkit::{Context, HandlerExt, ParentHandler, from_fn_async};
|
|
use serde::{Deserialize, Serialize};
|
|
use ts_rs::TS;
|
|
|
|
use crate::context::CliContext;
|
|
use crate::prelude::*;
|
|
use crate::registry::admin::display_signers;
|
|
use crate::registry::context::RegistryContext;
|
|
use crate::registry::signer::SignerInfo;
|
|
use crate::rpc_continuations::Guid;
|
|
use crate::util::serde::HandlerExtSerde;
|
|
|
|
pub fn signer_api<C: Context>() -> ParentHandler<C> {
|
|
ParentHandler::new()
|
|
.subcommand(
|
|
"add",
|
|
from_fn_async(add_version_signer)
|
|
.with_metadata("admin", Value::Bool(true))
|
|
.no_display()
|
|
.with_about("about.add-version-signer")
|
|
.with_call_remote::<CliContext>(),
|
|
)
|
|
.subcommand(
|
|
"remove",
|
|
from_fn_async(remove_version_signer)
|
|
.with_metadata("admin", Value::Bool(true))
|
|
.no_display()
|
|
.with_about("about.remove-version-signer")
|
|
.with_call_remote::<CliContext>(),
|
|
)
|
|
.subcommand(
|
|
"list",
|
|
from_fn_async(list_version_signers)
|
|
.with_metadata("authenticated", Value::Bool(false))
|
|
.with_display_serializable()
|
|
.with_custom_display_fn(|handle, result| display_signers(handle.params, result))
|
|
.with_about("about.list-version-signers")
|
|
.with_call_remote::<CliContext>(),
|
|
)
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize, Parser, TS)]
|
|
#[command(rename_all = "kebab-case")]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export)]
|
|
pub struct VersionSignerParams {
|
|
#[ts(type = "string")]
|
|
pub version: Version,
|
|
pub signer: Guid,
|
|
}
|
|
|
|
pub async fn add_version_signer(
|
|
ctx: RegistryContext,
|
|
VersionSignerParams { version, signer }: VersionSignerParams,
|
|
) -> Result<(), Error> {
|
|
ctx.db
|
|
.mutate(|db| {
|
|
ensure_code!(
|
|
db.as_index().as_signers().contains_key(&signer)?,
|
|
ErrorKind::InvalidRequest,
|
|
"unknown signer {signer}"
|
|
);
|
|
|
|
db.as_index_mut()
|
|
.as_os_mut()
|
|
.as_versions_mut()
|
|
.as_idx_mut(&version)
|
|
.or_not_found(&version)?
|
|
.as_authorized_mut()
|
|
.mutate(|s| Ok(s.insert(signer)))?;
|
|
|
|
Ok(())
|
|
})
|
|
.await
|
|
.result
|
|
}
|
|
|
|
pub async fn remove_version_signer(
|
|
ctx: RegistryContext,
|
|
VersionSignerParams { version, signer }: VersionSignerParams,
|
|
) -> Result<(), Error> {
|
|
ctx.db
|
|
.mutate(|db| {
|
|
if !db
|
|
.as_index_mut()
|
|
.as_os_mut()
|
|
.as_versions_mut()
|
|
.as_idx_mut(&version)
|
|
.or_not_found(&version)?
|
|
.as_authorized_mut()
|
|
.mutate(|s| Ok(s.remove(&signer)))?
|
|
{
|
|
return Err(Error::new(
|
|
eyre!("{}", t!("registry.os.version.signer-not-authorized", signer = signer, version = version)),
|
|
ErrorKind::NotFound,
|
|
));
|
|
}
|
|
|
|
Ok(())
|
|
})
|
|
.await
|
|
.result
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize, Parser, TS)]
|
|
#[command(rename_all = "kebab-case")]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(export)]
|
|
pub struct ListVersionSignersParams {
|
|
#[ts(type = "string")]
|
|
pub version: Version,
|
|
}
|
|
|
|
pub async fn list_version_signers(
|
|
ctx: RegistryContext,
|
|
ListVersionSignersParams { version }: ListVersionSignersParams,
|
|
) -> Result<BTreeMap<Guid, SignerInfo>, Error> {
|
|
let db = ctx.db.peek().await;
|
|
db.as_index()
|
|
.as_os()
|
|
.as_versions()
|
|
.as_idx(&version)
|
|
.or_not_found(&version)?
|
|
.as_authorized()
|
|
.de()?
|
|
.into_iter()
|
|
.filter_map(|guid| {
|
|
db.as_index()
|
|
.as_signers()
|
|
.as_idx(&guid)
|
|
.map(|s| s.de().map(|s| (guid, s)))
|
|
})
|
|
.collect()
|
|
}
|