Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert properties to an action #2751

Merged
merged 29 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f659745
update actions response types and partially implement in UI
MattDHill Oct 1, 2024
727650a
further remove diagnostic ui
MattDHill Oct 1, 2024
05adf5c
convert action response nested to array
MattDHill Oct 3, 2024
907d1ac
prepare action res modal for Alex
MattDHill Oct 3, 2024
a86e33d
Merge branch 'next/minor' of github.com:Start9Labs/start-os into refa…
MattDHill Oct 3, 2024
1379ac7
ad dproperties action for Bitcoin
MattDHill Oct 4, 2024
ed57ad5
feat: add action success dialog (#2753)
waterplea Oct 4, 2024
5904899
return null
dr-bonez Oct 4, 2024
3171fa1
remove properties from backend
dr-bonez Oct 9, 2024
5735234
misc fixes
dr-bonez Oct 9, 2024
325527b
make severity separate argument
dr-bonez Oct 9, 2024
1c5a988
rename ActionRequest to ActionRequestOptions
dr-bonez Oct 9, 2024
eb68fbd
add clearRequests
dr-bonez Oct 10, 2024
1c0827b
fix s9pk build
dr-bonez Oct 11, 2024
f326296
remove config and properties, introduce action requests
MattDHill Oct 14, 2024
24cdbf7
better ux, better moocks, include icons
MattDHill Oct 15, 2024
b67c800
Merge branch 'next/minor' into refactor/properties
dr-bonez Oct 16, 2024
fe0abe1
fix dependency types
dr-bonez Oct 16, 2024
c53332d
add variant for versionCompat
dr-bonez Oct 16, 2024
bb0eb8f
fix dep icon display and patch operation display
MattDHill Oct 16, 2024
8a7f8d5
misc fixes
dr-bonez Oct 16, 2024
92d063a
Merge branch 'refactor/properties' of github.com:Start9Labs/start-os …
dr-bonez Oct 16, 2024
8cf9eba
misc fixes
dr-bonez Oct 16, 2024
c0d7e28
alpha 12
dr-bonez Oct 16, 2024
84a364f
honor provided input to set values in action
MattDHill Oct 17, 2024
5f3ee14
fix: show full descriptions of action success items (#2758)
waterplea Oct 17, 2024
cc80a41
fix type
MattDHill Oct 17, 2024
12dc452
fix: fix build:deps command on Windows (#2752)
waterplea Oct 17, 2024
1e1e016
misc db compatibility fixes
dr-bonez Oct 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions container-runtime/src/Adapters/EffectCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ export function makeEffects(context: EffectContext): Effects {
stack: new Error().stack,
}) as ReturnType<T.Effects["bind"]>
},
clearBindings(...[]: Parameters<T.Effects["clearBindings"]>) {
return rpcRound("clear-bindings", {}) as ReturnType<
clearBindings(...[options]: Parameters<T.Effects["clearBindings"]>) {
return rpcRound("clear-bindings", { ...options }) as ReturnType<
T.Effects["clearBindings"]
>
},
clearServiceInterfaces(
...[]: Parameters<T.Effects["clearServiceInterfaces"]>
...[options]: Parameters<T.Effects["clearServiceInterfaces"]>
) {
return rpcRound("clear-service-interfaces", {}) as ReturnType<
return rpcRound("clear-service-interfaces", { ...options }) as ReturnType<
T.Effects["clearServiceInterfaces"]
>
},
Expand Down
11 changes: 5 additions & 6 deletions container-runtime/src/Adapters/RpcListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const matchRpcResult = anyOf(
),
}),
)

export type RpcResult = typeof matchRpcResult._TYPE
type SocketResponse = ({ jsonrpc: "2.0"; id: IdType } & RpcResult) | null

Expand Down Expand Up @@ -88,7 +89,7 @@ const sandboxRunType = object(
const callbackType = object({
method: literal("callback"),
params: object({
callback: number,
id: number,
args: array,
}),
})
Expand Down Expand Up @@ -288,8 +289,8 @@ export class RpcListener {

return handleRpc(id, result)
})
.when(callbackType, async ({ params: { callback, args } }) => {
this.callCallback(callback, args)
.when(callbackType, async ({ params: { id, args } }) => {
this.callCallback(id, args)
return null
})
.when(startType, async ({ id }) => {
Expand Down Expand Up @@ -410,7 +411,7 @@ export class RpcListener {
input: any,
) {
const ensureResultTypeShape = (
result: void | T.ActionInput | T.PropertiesReturn | T.ActionResult | null,
result: void | T.ActionInput | T.ActionResult | null,
): { result: any } => {
if (isResult(result)) return result
return { result }
Expand All @@ -428,8 +429,6 @@ export class RpcListener {
return system.createBackup(effects, timeout || null)
case "/backup/restore":
return system.restoreBackup(effects, timeout || null)
case "/properties":
return system.properties(effects, timeout || null)
case "/packageInit":
return system.packageInit(effects, timeout || null)
case "/packageUninit":
Expand Down
107 changes: 93 additions & 14 deletions container-runtime/src/Adapters/Systems/SystemForEmbassy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,34 @@ type OldGetConfigRes = {
spec: OldConfigSpec
}

export type PropertiesValue =
| {
/** The type of this value, either "string" or "object" */
type: "object"
/** A nested mapping of values. The user will experience this as a nested page with back button */
value: { [k: string]: PropertiesValue }
/** (optional) A human readable description of the new set of values */
description: string | null
}
| {
/** The type of this value, either "string" or "object" */
type: "string"
/** The value to display to the user */
value: string
/** A human readable description of the value */
description: string | null
/** Whether or not to mask the value, for example, when displaying a password */
masked: boolean | null
/** Whether or not to include a button for copying the value to clipboard */
copyable: boolean | null
/** Whether or not to include a button for displaying the value as a QR code */
qr: boolean | null
}

export type PropertiesReturn = {
[key: string]: PropertiesValue
}

export type PackagePropertiesV2 = {
[name: string]: PackagePropertyObject | PackagePropertyString
}
Expand All @@ -157,7 +185,7 @@ export type PackagePropertyObject = {

const asProperty_ = (
x: PackagePropertyString | PackagePropertyObject,
): T.PropertiesValue => {
): PropertiesValue => {
if (x.type === "object") {
return {
...x,
Expand All @@ -177,7 +205,7 @@ const asProperty_ = (
...x,
}
}
const asProperty = (x: PackagePropertiesV2): T.PropertiesReturn =>
const asProperty = (x: PackagePropertiesV2): PropertiesReturn =>
Object.fromEntries(
Object.entries(x).map(([key, value]) => [key, asProperty_(value)]),
)
Expand Down Expand Up @@ -214,6 +242,31 @@ const matchProperties = object({
data: matchPackageProperties,
})

function convertProperties(
name: string,
value: PropertiesValue,
): T.ActionResultV1 {
if (value.type === "string") {
return {
type: "string",
name,
description: value.description,
copyable: value.copyable || false,
masked: value.masked || false,
qr: value.qr || false,
value: value.value,
}
}
return {
type: "object",
name,
description: value.description || undefined,
value: Object.entries(value.value).map(([name, value]) =>
convertProperties(name, value),
),
}
}

const DEFAULT_REGISTRY = "https://registry.start9.com"
export class SystemForEmbassy implements System {
currentRunning: MainLoop | undefined
Expand Down Expand Up @@ -245,6 +298,9 @@ export class SystemForEmbassy implements System {
await this.dependenciesAutoconfig(effects, depId, null)
}
}
await effects.setMainStatus({ status: "stopped" })
await this.exportActions(effects)
await this.exportNetwork(effects)
}

async exit(): Promise<void> {
Expand Down Expand Up @@ -281,10 +337,15 @@ export class SystemForEmbassy implements System {
await effects.setDataVersion({
version: ExtendedVersion.parseEmver(this.manifest.version).toString(),
})
} else {
await effects.action.request({
packageId: this.manifest.id,
actionId: "config",
severity: "critical",
replayId: "needs-config",
reason: "This service must be configured before it can be run",
})
}
await effects.setMainStatus({ status: "stopped" })
await this.exportActions(effects)
await this.exportNetwork(effects)
}
async exportNetwork(effects: Effects) {
for (const [id, interfaceValue] of Object.entries(
Expand Down Expand Up @@ -375,6 +436,8 @@ export class SystemForEmbassy implements System {
if (actionId === "config") {
const config = await this.getConfig(effects, timeoutMs)
return { spec: config.spec, value: config.config }
} else if (actionId === "properties") {
return null
} else {
const oldSpec = this.manifest.actions?.[actionId]?.["input-spec"]
if (!oldSpec) return null
Expand All @@ -393,6 +456,17 @@ export class SystemForEmbassy implements System {
if (actionId === "config") {
await this.setConfig(effects, input, timeoutMs)
return null
} else if (actionId === "properties") {
return {
version: "1",
type: "object",
name: "Properties",
description:
"Runtime information, credentials, and other values of interest",
value: Object.entries(await this.properties(effects, timeoutMs)).map(
([name, value]) => convertProperties(name, value),
),
}
} else {
return this.action(effects, actionId, input, timeoutMs)
}
Expand All @@ -405,17 +479,21 @@ export class SystemForEmbassy implements System {
if (manifest.config) {
actions.config = {
name: "Configure",
description: "Edit the configuration of this service",
description: `Customize ${manifest.title}`,
"allowed-statuses": ["running", "stopped"],
"input-spec": {},
implementation: { type: "script", args: [] },
}
await effects.action.request({
packageId: this.manifest.id,
actionId: "config",
replayId: "needs-config",
description: "This service must be configured before it can be run",
})
}
if (manifest.properties) {
actions.properties = {
name: "Properties",
description:
"Runtime information, credentials, and other values of interest",
"allowed-statuses": ["running", "stopped"],
"input-spec": null,
implementation: { type: "script", args: [] },
}
}
for (const [actionId, action] of Object.entries(actions)) {
const hasRunning = !!action["allowed-statuses"].find(
Expand Down Expand Up @@ -694,7 +772,7 @@ export class SystemForEmbassy implements System {
async properties(
effects: Effects,
timeoutMs: number | null,
): Promise<T.PropertiesReturn> {
): Promise<PropertiesReturn> {
// TODO BLU-J set the properties ever so often
const setConfigValue = this.manifest.properties
if (!setConfigValue) throw new Error("There is no properties")
Expand Down Expand Up @@ -867,7 +945,8 @@ export class SystemForEmbassy implements System {
actionId: "config",
packageId: id,
replayId: `${id}/config`,
description: `Configure this dependency for the needs of ${this.manifest.title}`,
severity: "important",
reason: `Configure this dependency for the needs of ${this.manifest.title}`,
input: {
kind: "partial",
value: diff.diff,
Expand Down
6 changes: 0 additions & 6 deletions container-runtime/src/Adapters/Systems/SystemForStartOs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ export class SystemForStartOs implements System {
effects,
}))
}
properties(
effects: Effects,
timeoutMs: number | null,
): Promise<T.PropertiesReturn> {
throw new Error("Method not implemented.")
}
getActionInput(
effects: Effects,
id: string,
Expand Down
5 changes: 0 additions & 5 deletions container-runtime/src/Interfaces/System.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export type Procedure =
| "/packageUninit"
| "/backup/create"
| "/backup/restore"
| "/properties"
| `/actions/${string}/getInput`
| `/actions/${string}/run`

Expand All @@ -30,10 +29,6 @@ export type System = {

createBackup(effects: T.Effects, timeoutMs: number | null): Promise<void>
restoreBackup(effects: T.Effects, timeoutMs: number | null): Promise<void>
properties(
effects: Effects,
timeoutMs: number | null,
): Promise<T.PropertiesReturn>
runAction(
effects: Effects,
actionId: string,
Expand Down
3 changes: 2 additions & 1 deletion container-runtime/src/Models/CallbackHolder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { T } from "@start9labs/start-sdk"

const CallbackIdCell = { inc: 0 }
const CallbackIdCell = { inc: 1 }

const callbackRegistry = new FinalizationRegistry(
async (options: { cbs: Map<number, Function>; effects: T.Effects }) => {
Expand All @@ -23,6 +23,7 @@ export class CallbackHolder {
return
}
const id = this.newId()
console.error("adding callback", id)
this.callbacks.set(id, callback)
if (this.effects)
callbackRegistry.register(this, {
Expand Down
2 changes: 0 additions & 2 deletions container-runtime/src/Models/JsonPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export const jsonPath = some(
"/packageUninit",
"/backup/create",
"/backup/restore",
"/actions/metadata",
"/properties",
),
string.refine(isNestedPath, "isNestedPath"),
)
Expand Down
2 changes: 0 additions & 2 deletions core/models/src/procedure_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub enum ProcedureName {
GetConfig,
SetConfig,
CreateBackup,
Properties,
RestoreBackup,
GetActionInput(ActionId),
RunAction(ActionId),
Expand All @@ -23,7 +22,6 @@ 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::RunAction(id) => format!("/actions/{}/run", id),
ProcedureName::GetActionInput(id) => format!("/actions/{}/getInput", id),
Expand Down
Loading