mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 14:29:45 +00:00
Add some extra export action
This commit is contained in:
@@ -29,6 +29,7 @@ import {
|
|||||||
import { HostSystemStartOs } from "../../HostSystemStartOs"
|
import { HostSystemStartOs } from "../../HostSystemStartOs"
|
||||||
import { JsonPath, unNestPath } from "../../../Models/JsonPath"
|
import { JsonPath, unNestPath } from "../../../Models/JsonPath"
|
||||||
import { RpcResult, matchRpcResult } from "../../RpcListener"
|
import { RpcResult, matchRpcResult } from "../../RpcListener"
|
||||||
|
import { InputSpec } from "@start9labs/start-sdk/cjs/sdk/lib/config/configTypes"
|
||||||
|
|
||||||
type Optional<A> = A | undefined | null
|
type Optional<A> = A | undefined | null
|
||||||
function todo(): never {
|
function todo(): never {
|
||||||
@@ -259,6 +260,35 @@ export class SystemForEmbassy implements System {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (previousVersion) await this.migration(effects, previousVersion)
|
if (previousVersion) await this.migration(effects, previousVersion)
|
||||||
await effects.setMainStatus({ status: "stopped" })
|
await effects.setMainStatus({ status: "stopped" })
|
||||||
|
await this.exportActions(effects)
|
||||||
|
}
|
||||||
|
async exportActions(effects: HostSystemStartOs) {
|
||||||
|
const manifest = this.manifest
|
||||||
|
if (!manifest.actions) return
|
||||||
|
for (const [actionId, action] of Object.entries(manifest.actions)) {
|
||||||
|
const hasRunning = !!action["allowed-statuses"].find(
|
||||||
|
(x) => x === "running",
|
||||||
|
)
|
||||||
|
const hasStopped = !!action["allowed-statuses"].find(
|
||||||
|
(x) => x === "stopped",
|
||||||
|
)
|
||||||
|
// prettier-ignore
|
||||||
|
const allowedStatuses = hasRunning && hasStopped ? "any":
|
||||||
|
hasRunning ? "onlyRunning" :
|
||||||
|
"onlyStopped"
|
||||||
|
await effects.exportAction({
|
||||||
|
id: actionId,
|
||||||
|
metadata: {
|
||||||
|
name: action.name,
|
||||||
|
description: action.description,
|
||||||
|
warning: action.warning || null,
|
||||||
|
input: action["input-spec"] as InputSpec,
|
||||||
|
disabled: false,
|
||||||
|
allowedStatuses,
|
||||||
|
group: null,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private async uninit(
|
private async uninit(
|
||||||
effects: HostSystemStartOs,
|
effects: HostSystemStartOs,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::collections::{BTreeMap, BTreeSet};
|
|||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use emver::VersionRange;
|
use emver::VersionRange;
|
||||||
use imbl_value::InternedString;
|
use imbl_value::InternedString;
|
||||||
use models::{DataUrl, HealthCheckId, HostId, PackageId};
|
use models::{ActionId, DataUrl, HealthCheckId, HostId, PackageId};
|
||||||
use patch_db::json_ptr::JsonPointer;
|
use patch_db::json_ptr::JsonPointer;
|
||||||
use patch_db::HasModel;
|
use patch_db::HasModel;
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
@@ -293,6 +293,28 @@ pub struct InstallingInfo {
|
|||||||
pub new_manifest: Manifest,
|
pub new_manifest: Manifest,
|
||||||
pub progress: FullProgress,
|
pub progress: FullProgress,
|
||||||
}
|
}
|
||||||
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
|
||||||
|
#[ts(export)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub enum AllowedStatuses {
|
||||||
|
OnlyRunning, // onlyRunning
|
||||||
|
OnlyStopped,
|
||||||
|
Any,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize, HasModel, TS)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
#[model = "Model<Self>"]
|
||||||
|
pub struct ActionMetadata {
|
||||||
|
name: String,
|
||||||
|
description: String,
|
||||||
|
warning: Option<String>,
|
||||||
|
#[ts(type = "any")]
|
||||||
|
input: Value,
|
||||||
|
disabled: bool,
|
||||||
|
allowedStatuses: AllowedStatuses,
|
||||||
|
group: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, HasModel, TS)]
|
#[derive(Debug, Deserialize, Serialize, HasModel, TS)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
@@ -312,6 +334,7 @@ pub struct PackageDataEntry {
|
|||||||
pub hosts: HostInfo,
|
pub hosts: HostInfo,
|
||||||
#[ts(type = "string[]")]
|
#[ts(type = "string[]")]
|
||||||
pub store_exposed_dependents: Vec<JsonPointer>,
|
pub store_exposed_dependents: Vec<JsonPointer>,
|
||||||
|
pub exposed_actions: BTreeMap<ActionId, ActionMetadata>,
|
||||||
}
|
}
|
||||||
impl AsRef<PackageDataEntry> for PackageDataEntry {
|
impl AsRef<PackageDataEntry> for PackageDataEntry {
|
||||||
fn as_ref(&self) -> &PackageDataEntry {
|
fn as_ref(&self) -> &PackageDataEntry {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use ts_rs::TS;
|
|||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::db::model::package::{
|
use crate::db::model::package::{
|
||||||
CurrentDependencies, CurrentDependencyInfo, CurrentDependencyKind,
|
ActionMetadata, CurrentDependencies, CurrentDependencyInfo, CurrentDependencyKind,
|
||||||
};
|
};
|
||||||
use crate::disk::mount::filesystem::idmapped::IdMapped;
|
use crate::disk::mount::filesystem::idmapped::IdMapped;
|
||||||
use crate::disk::mount::filesystem::loop_dev::LoopDev;
|
use crate::disk::mount::filesystem::loop_dev::LoopDev;
|
||||||
@@ -254,14 +254,6 @@ struct ListServiceInterfacesParams {
|
|||||||
struct RemoveAddressParams {
|
struct RemoveAddressParams {
|
||||||
id: String,
|
id: String,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
|
|
||||||
#[ts(export)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
enum AllowedStatuses {
|
|
||||||
OnlyRunning, // onlyRunning
|
|
||||||
OnlyStopped,
|
|
||||||
Any,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
|
||||||
#[ts(export)]
|
#[ts(export)]
|
||||||
@@ -274,21 +266,9 @@ struct ExportActionParams {
|
|||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
|
||||||
#[ts(export)]
|
#[ts(export)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct ActionMetadata {
|
|
||||||
name: String,
|
|
||||||
description: String,
|
|
||||||
warning: Option<String>,
|
|
||||||
disabled: bool,
|
|
||||||
#[ts(type = "{[key: string]: any}")]
|
|
||||||
input: Value,
|
|
||||||
allowed_statuses: AllowedStatuses,
|
|
||||||
group: Option<String>,
|
|
||||||
}
|
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
|
|
||||||
#[ts(export)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
struct RemoveActionParams {
|
struct RemoveActionParams {
|
||||||
id: String,
|
#[ts(type = "string")]
|
||||||
|
id: ActionId,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)]
|
||||||
#[ts(export)]
|
#[ts(export)]
|
||||||
@@ -387,11 +367,48 @@ async fn list_service_interfaces(
|
|||||||
async fn remove_address(context: EffectContext, data: RemoveAddressParams) -> Result<Value, Error> {
|
async fn remove_address(context: EffectContext, data: RemoveAddressParams) -> Result<Value, Error> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
async fn export_action(context: EffectContext, data: ExportActionParams) -> Result<Value, Error> {
|
async fn export_action(context: EffectContext, data: ExportActionParams) -> Result<(), Error> {
|
||||||
todo!()
|
let context = context.deref()?;
|
||||||
|
let package_id = context.id.clone();
|
||||||
|
context
|
||||||
|
.ctx
|
||||||
|
.db
|
||||||
|
.mutate(|db| {
|
||||||
|
let model = db
|
||||||
|
.as_public_mut()
|
||||||
|
.as_package_data_mut()
|
||||||
|
.as_idx_mut(&package_id)
|
||||||
|
.or_not_found(&package_id)?
|
||||||
|
.as_exposed_actions_mut();
|
||||||
|
let mut value = model.de()?;
|
||||||
|
value
|
||||||
|
.insert(data.id, data.metadata)
|
||||||
|
.map(|_| ())
|
||||||
|
.unwrap_or_default();
|
||||||
|
model.ser(&value)
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn remove_action(context: EffectContext, data: RemoveActionParams) -> Result<Value, Error> {
|
async fn remove_action(context: EffectContext, data: RemoveActionParams) -> Result<(), Error> {
|
||||||
todo!()
|
let context = context.deref()?;
|
||||||
|
let package_id = context.id.clone();
|
||||||
|
context
|
||||||
|
.ctx
|
||||||
|
.db
|
||||||
|
.mutate(|db| {
|
||||||
|
let model = db
|
||||||
|
.as_public_mut()
|
||||||
|
.as_package_data_mut()
|
||||||
|
.as_idx_mut(&package_id)
|
||||||
|
.or_not_found(&package_id)?
|
||||||
|
.as_exposed_actions_mut();
|
||||||
|
let mut value = model.de()?;
|
||||||
|
value.remove(&data.id).map(|_| ()).unwrap_or_default();
|
||||||
|
model.ser(&value)
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn reverse_proxy(context: EffectContext, data: ReverseProxyParams) -> Result<Value, Error> {
|
async fn reverse_proxy(context: EffectContext, data: ReverseProxyParams) -> Result<Value, Error> {
|
||||||
todo!()
|
todo!()
|
||||||
|
|||||||
Reference in New Issue
Block a user