diff --git a/core/startos/bindings/AddressInfo.ts b/core/startos/bindings/AddressInfo.ts new file mode 100644 index 000000000..9d4c8ee6e --- /dev/null +++ b/core/startos/bindings/AddressInfo.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { BindOptions } from "./BindOptions"; + +export interface AddressInfo { username: string | null, hostId: string, bindOptions: BindOptions, suffix: string, } \ No newline at end of file diff --git a/core/startos/bindings/AllowedStatuses.ts b/core/startos/bindings/AllowedStatuses.ts new file mode 100644 index 000000000..87d122f70 --- /dev/null +++ b/core/startos/bindings/AllowedStatuses.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type AllowedStatuses = "only-running" | "only-stopped" | "any" | "disabled"; \ No newline at end of file diff --git a/core/startos/bindings/BindOptions.ts b/core/startos/bindings/BindOptions.ts new file mode 100644 index 000000000..029be6a16 --- /dev/null +++ b/core/startos/bindings/BindOptions.ts @@ -0,0 +1,5 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { AddSslOptions } from "./AddSslOptions"; +import type { BindOptionsSecure } from "./BindOptionsSecure"; + +export interface BindOptions { scheme: string | null, preferredExternalPort: number, addSsl: AddSslOptions | null, secure: BindOptionsSecure | null, } \ No newline at end of file diff --git a/core/startos/bindings/BindOptionsSecure.ts b/core/startos/bindings/BindOptionsSecure.ts new file mode 100644 index 000000000..00bfd7dd2 --- /dev/null +++ b/core/startos/bindings/BindOptionsSecure.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface BindOptionsSecure { ssl: boolean, } \ No newline at end of file diff --git a/core/startos/bindings/BindParams.ts b/core/startos/bindings/BindParams.ts index 8d8eef6b4..f48f848b8 100644 --- a/core/startos/bindings/BindParams.ts +++ b/core/startos/bindings/BindParams.ts @@ -1,5 +1,6 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { AddSslOptions } from "./AddSslOptions"; import type { BindKind } from "./BindKind"; +import type { BindOptionsSecure } from "./BindOptionsSecure"; -export interface BindParams { kind: BindKind, id: string, internalPort: number, scheme: string, preferredExternalPort: number, addSsl: AddSslOptions | null, secure: boolean, ssl: boolean, } \ No newline at end of file +export interface BindParams { kind: BindKind, id: string, internalPort: number, scheme: string, preferredExternalPort: number, addSsl: AddSslOptions | null, secure: BindOptionsSecure | null, } \ No newline at end of file diff --git a/core/startos/bindings/ExportActionParams.ts b/core/startos/bindings/ExportActionParams.ts new file mode 100644 index 000000000..413a63183 --- /dev/null +++ b/core/startos/bindings/ExportActionParams.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { AllowedStatuses } from "./AllowedStatuses"; + +export interface ExportActionParams { name: string, description: string, id: string, input: {[key: string]: any}, allowedStatuses: AllowedStatuses, group: string | null, } \ No newline at end of file diff --git a/core/startos/bindings/ExportServiceInterfaceParams.ts b/core/startos/bindings/ExportServiceInterfaceParams.ts new file mode 100644 index 000000000..d30cce9db --- /dev/null +++ b/core/startos/bindings/ExportServiceInterfaceParams.ts @@ -0,0 +1,5 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { AddressInfo } from "./AddressInfo"; +import type { ServiceInterfaceType } from "./ServiceInterfaceType"; + +export interface ExportServiceInterfaceParams { id: string, name: string, description: string, hasPrimary: boolean, disabled: boolean, masked: boolean, addressInfo: AddressInfo, type: ServiceInterfaceType, } \ No newline at end of file diff --git a/core/startos/bindings/GetPrimaryUrlParams.ts b/core/startos/bindings/GetPrimaryUrlParams.ts new file mode 100644 index 000000000..40fe7f154 --- /dev/null +++ b/core/startos/bindings/GetPrimaryUrlParams.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { Callback } from "./Callback"; + +export interface GetPrimaryUrlParams { packageId: string | null, serviceInterfaceId: string, callback: Callback, } \ No newline at end of file diff --git a/core/startos/bindings/GetServicePortForwardParams.ts b/core/startos/bindings/GetServicePortForwardParams.ts new file mode 100644 index 000000000..270fcb709 --- /dev/null +++ b/core/startos/bindings/GetServicePortForwardParams.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface GetServicePortForwardParams { packageId: string | null, internalPort: number, } \ No newline at end of file diff --git a/core/startos/bindings/GetSystemSmtpParams.ts b/core/startos/bindings/GetSystemSmtpParams.ts new file mode 100644 index 000000000..617fd7fa0 --- /dev/null +++ b/core/startos/bindings/GetSystemSmtpParams.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { Callback } from "./Callback"; + +export interface GetSystemSmtpParams { callback: Callback, } \ No newline at end of file diff --git a/core/startos/bindings/ListServiceInterfacesParams.ts b/core/startos/bindings/ListServiceInterfacesParams.ts new file mode 100644 index 000000000..33db3f129 --- /dev/null +++ b/core/startos/bindings/ListServiceInterfacesParams.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { Callback } from "./Callback"; + +export interface ListServiceInterfacesParams { packageId: string | null, callback: Callback, } \ No newline at end of file diff --git a/core/startos/bindings/MountParams.ts b/core/startos/bindings/MountParams.ts new file mode 100644 index 000000000..26e8373c7 --- /dev/null +++ b/core/startos/bindings/MountParams.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { MountTarget } from "./MountTarget"; + +export interface MountParams { location: string, target: MountTarget, } \ No newline at end of file diff --git a/core/startos/bindings/MountTarget.ts b/core/startos/bindings/MountTarget.ts new file mode 100644 index 000000000..41c026deb --- /dev/null +++ b/core/startos/bindings/MountTarget.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface MountTarget { packageId: string, volumeId: string, path: string, readonly: boolean, } \ No newline at end of file diff --git a/core/startos/bindings/RemoveActionParams.ts b/core/startos/bindings/RemoveActionParams.ts new file mode 100644 index 000000000..3e0c3c48d --- /dev/null +++ b/core/startos/bindings/RemoveActionParams.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface RemoveActionParams { id: string, } \ No newline at end of file diff --git a/core/startos/bindings/RemoveAddressParams.ts b/core/startos/bindings/RemoveAddressParams.ts new file mode 100644 index 000000000..1bc483f89 --- /dev/null +++ b/core/startos/bindings/RemoveAddressParams.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface RemoveAddressParams { id: string, } \ No newline at end of file diff --git a/core/startos/bindings/ReverseProxyBind.ts b/core/startos/bindings/ReverseProxyBind.ts new file mode 100644 index 000000000..3f9e0dc25 --- /dev/null +++ b/core/startos/bindings/ReverseProxyBind.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface ReverseProxyBind { ip: string | null, port: number, ssl: boolean, } \ No newline at end of file diff --git a/core/startos/bindings/ReverseProxyDestination.ts b/core/startos/bindings/ReverseProxyDestination.ts new file mode 100644 index 000000000..a6003e189 --- /dev/null +++ b/core/startos/bindings/ReverseProxyDestination.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface ReverseProxyDestination { ip: string | null, port: number, ssl: boolean, } \ No newline at end of file diff --git a/core/startos/bindings/ReverseProxyHttp.ts b/core/startos/bindings/ReverseProxyHttp.ts new file mode 100644 index 000000000..5c1d0aa1b --- /dev/null +++ b/core/startos/bindings/ReverseProxyHttp.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface ReverseProxyHttp { headers: null | {[key: string]: string}, } \ No newline at end of file diff --git a/core/startos/bindings/ReverseProxyParams.ts b/core/startos/bindings/ReverseProxyParams.ts new file mode 100644 index 000000000..bde3034e9 --- /dev/null +++ b/core/startos/bindings/ReverseProxyParams.ts @@ -0,0 +1,6 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { ReverseProxyBind } from "./ReverseProxyBind"; +import type { ReverseProxyDestination } from "./ReverseProxyDestination"; +import type { ReverseProxyHttp } from "./ReverseProxyHttp"; + +export interface ReverseProxyParams { bind: ReverseProxyBind, dst: ReverseProxyDestination, http: ReverseProxyHttp, } \ No newline at end of file diff --git a/core/startos/bindings/ServiceInterfaceType.ts b/core/startos/bindings/ServiceInterfaceType.ts new file mode 100644 index 000000000..74372d4ad --- /dev/null +++ b/core/startos/bindings/ServiceInterfaceType.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type ServiceInterfaceType = "ui" | "p2p" | "api"; \ No newline at end of file diff --git a/core/startos/src/service/service_effect_handler.rs b/core/startos/src/service/service_effect_handler.rs index 4dd086e2c..6e9610c8a 100644 --- a/core/startos/src/service/service_effect_handler.rs +++ b/core/startos/src/service/service_effect_handler.rs @@ -184,11 +184,48 @@ struct GetServicePortForwardParams { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] #[ts(export)] #[serde(rename_all = "camelCase")] +struct BindOptionsSecure { + ssl: bool, +} +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] +#[ts(export)] +#[serde(rename_all = "camelCase")] +struct BindOptions { + scheme: Option, + preferred_external_port: u32, + add_ssl: Option, + secure: Option, +} +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] +#[ts(export)] +#[serde(rename_all = "camelCase")] +struct AddressInfo { + username: Option, + host_id: String, + bind_options: BindOptions, + suffix: String, +} + +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] +#[ts(export)] +#[serde(rename_all = "camelCase")] +enum ServiceInterfaceType { + Ui, + P2p, + Api, +} +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] +#[ts(export)] +#[serde(rename_all = "camelCase")] struct ExportServiceInterfaceParams { - #[ts(type = "string | null")] - package_id: Option, - service_interface_id: String, - callback: Callback, + id: String, + name: String, + description: String, + has_primary: bool, + disabled: bool, + masked: bool, + address_info: AddressInfo, + r#type: ServiceInterfaceType, } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, TS)] #[ts(export)] @@ -277,8 +314,8 @@ struct ReverseProxyParams { #[serde(rename_all = "camelCase")] struct MountTarget { #[ts(type = "string")] - packageId: PackageId, - volumeId: String, + package_id: PackageId, + volume_id: String, path: String, readonly: bool, } @@ -399,8 +436,7 @@ struct BindParams { scheme: String, preferred_external_port: u32, add_ssl: Option, - secure: bool, - ssl: bool, + secure: Option, } async fn bind(_: AnyContext, BindParams { .. }: BindParams) -> Result { todo!() diff --git a/sdk/lib/interfaces/Host.ts b/sdk/lib/interfaces/Host.ts index 4c3f43634..cb6fa9f9a 100644 --- a/sdk/lib/interfaces/Host.ts +++ b/sdk/lib/interfaces/Host.ts @@ -59,12 +59,13 @@ type AddSslOptions = { preferredExternalPort: number addXForwardedHeaders: boolean | null /** default: false */ } -type Security = { secure: false; ssl: false } | { secure: true; ssl: boolean } +type Security = { ssl: boolean } export type BindOptions = { scheme: Scheme preferredExternalPort: number addSsl: AddSslOptions | null -} & Security + secure: Security | null +} type KnownProtocols = typeof knownProtocols type ProtocolsWithSslVariants = { [K in keyof KnownProtocols]: KnownProtocols[K] extends { @@ -79,14 +80,15 @@ type NotProtocolsWithSslVariants = Exclude< > type BindOptionsByKnownProtocol = - | ({ + | { protocol: ProtocolsWithSslVariants - preferredExternalPort?: number + preferredExternalPort: number | null scheme: Scheme | null - } & ({ noAddSsl: true } | { addSsl?: Partial })) + addSsl: Partial | null + } | { protocol: NotProtocolsWithSslVariants - preferredExternalPort?: number + preferredExternalPort: number | null scheme: Scheme | null addSsl: AddSslOptions | null } @@ -120,17 +122,12 @@ export class Host { private async bindPortForUnknown( internalPort: number, - options: - | ({ - scheme: Scheme - preferredExternalPort: number - addSsl: AddSslOptions | null - } & { secure: false; ssl: false }) - | ({ - scheme: Scheme - preferredExternalPort: number - addSsl: AddSslOptions | null - } & { secure: true; ssl: boolean }), + options: { + scheme: Scheme + preferredExternalPort: number + addSsl: AddSslOptions | null + secure: { ssl: boolean } | null + }, ) { await this.options.effects.bind({ kind: this.options.kind, @@ -154,18 +151,13 @@ export class Host { knownProtocols[options.protocol].defaultPort const addSsl = this.getAddSsl(options, protoInfo) - const security: Security = !protoInfo.secure - ? { - secure: protoInfo.secure, - ssl: protoInfo.ssl, - } - : { secure: false, ssl: false } + const secure: Security | null = !protoInfo.secure ? null : { ssl: false } const newOptions = { scheme, preferredExternalPort, addSsl, - ...security, + secure, } await this.options.effects.bind({ diff --git a/sdk/lib/test/host.test.ts b/sdk/lib/test/host.test.ts index 89776cf66..461d4a82a 100644 --- a/sdk/lib/test/host.test.ts +++ b/sdk/lib/test/host.test.ts @@ -10,6 +10,8 @@ describe("host", () => { const fooOrigin = await foo.bindPort(80, { protocol: "http" as const, scheme: null, + addSsl: null, + preferredExternalPort: null, }) const fooInterface = new ServiceInterfaceBuilder({ effects, diff --git a/sdk/lib/test/startosTypeValidation.test.ts b/sdk/lib/test/startosTypeValidation.test.ts index ae6931bdc..5f1be60bb 100644 --- a/sdk/lib/test/startosTypeValidation.test.ts +++ b/sdk/lib/test/startosTypeValidation.test.ts @@ -14,41 +14,24 @@ import { GetSslCertificateParams } from "../../../core/startos/bindings/GetSslCe import { GetSslKeyParams } from "../../../core/startos/bindings/GetSslKeyParams" import { GetServiceInterfaceParams } from "../../../core/startos/bindings/GetServiceInterfaceParams" import { SetDependenciesParams } from "../../../core/startos/bindings/SetDependenciesParams" - +import { GetSystemSmtpParams } from "../../../core/startos/bindings/GetSystemSmtpParams" +import { GetServicePortForwardParams } from "../../../core/startos/bindings/GetServicePortForwardParams" +import { ExportServiceInterfaceParams } from "../../../core/startos/bindings/ExportServiceInterfaceParams" +import { GetPrimaryUrlParams } from "../../../core/startos/bindings/GetPrimaryUrlParams" +import { ListServiceInterfacesParams } from "../../../core/startos/bindings/ListServiceInterfacesParams" +import { RemoveAddressParams } from "../../../core/startos/bindings/RemoveAddressParams" +import { ExportActionParams } from "../../../core/startos/bindings/ExportActionParams" +import { RemoveActionParams } from "../../../core/startos/bindings/RemoveActionParams" +import { ReverseProxyParams } from "../../../core/startos/bindings/ReverseProxyParams" +import { MountParams } from "../../../core/startos/bindings/MountParams" function typeEquality(_a: ExpectedType) {} describe("startosTypeValidation ", () => { test(`checking the params match`, () => { const testInput: any = {} typeEquality<{ - [K in keyof Effects & - ( - | "gitInfo" - | "echo" - | "chroot" - | "exists" - | "executeAction" - | "getConfigured" - | "stopped" - | "running" - | "restart" - | "shutdown" - | "setConfigured" - | "setMainStatus" - | "setHealth" - | "getStore" - | "setStore" - | "exposeForDependents" - | "exposeUi" - | "createOverlayedImage" - | "destroyOverlayedImage" - | "getSslCertificate" - | "getSslKey" - | "getServiceInterface" - | "clearBindings" - | "bind" - | "getHostInfo" - | "setDependencies" - )]: Effects[K] extends Function ? Parameters[0] : never + [K in keyof Effects]: Effects[K] extends (args: infer A) => any + ? A + : never }>({ executeAction: {} as ExecuteAction, createOverlayedImage: {} as CreateOverlayedImageParams, @@ -70,6 +53,19 @@ describe("startosTypeValidation ", () => { getSslKey: {} as GetSslKeyParams, getServiceInterface: {} as GetServiceInterfaceParams, setDependencies: {} as SetDependenciesParams, + store: {} as never, + getSystemSmtp: {} as GetSystemSmtpParams, + getContainerIp: undefined, + getServicePortForward: {} as GetServicePortForwardParams, + clearServiceInterfaces: undefined, + exportServiceInterface: {} as ExportServiceInterfaceParams, + getPrimaryUrl: {} as GetPrimaryUrlParams, + listServiceInterfaces: {} as ListServiceInterfacesParams, + removeAddress: {} as RemoveAddressParams, + exportAction: {} as ExportActionParams, + removeAction: {} as RemoveActionParams, + reverseProxy: {} as ReverseProxyParams, + mount: {} as MountParams, }) typeEquality[0]>( testInput as ExecuteAction, diff --git a/sdk/lib/types.ts b/sdk/lib/types.ts index eb7ea27bf..a578e711a 100644 --- a/sdk/lib/types.ts +++ b/sdk/lib/types.ts @@ -302,8 +302,7 @@ export type Effects = { scheme: Scheme preferredExternalPort: number addSsl: AddSslOptions | null - secure: boolean - ssl: boolean + secure: { ssl: boolean } | null }): Promise /** Retrieves the current hostname(s) associated with a host id */ // getHostInfo(options: { @@ -491,9 +490,7 @@ export type Effects = { } http: { // optional, will do TCP layer proxy only if not present - headers: - | ((headers: Record) => Record) - | null + headers: Record | null } | null }): Promise<{ stop(): Promise }> restart(): void diff --git a/web/projects/ui/src/app/services/api/api.fixures.ts b/web/projects/ui/src/app/services/api/api.fixures.ts index 7cf449664..ea9fcc1c1 100644 --- a/web/projects/ui/src/app/services/api/api.fixures.ts +++ b/web/projects/ui/src/app/services/api/api.fixures.ts @@ -1789,8 +1789,7 @@ export module Mock { preferredExternalPort: 443, scheme: 'https', }, - secure: false, - ssl: false, + secure: null, }, suffix: '', }, @@ -1862,8 +1861,7 @@ export module Mock { preferredExternalPort: 443, scheme: 'https', }, - secure: false, - ssl: false, + secure: null, }, suffix: '', }, @@ -1931,8 +1929,7 @@ export module Mock { scheme: 'bitcoin', preferredExternalPort: 8333, addSsl: null, - secure: true, - ssl: false, + secure: { ssl: false }, }, suffix: '', }, @@ -2038,8 +2035,7 @@ export module Mock { preferredExternalPort: 443, scheme: 'https', }, - secure: true, - ssl: true, + secure: { ssl: true }, }, suffix: '', }, @@ -2187,8 +2183,7 @@ export module Mock { scheme: 'grpc', preferredExternalPort: 10009, addSsl: null, - secure: true, - ssl: true, + secure: { ssl: true }, }, suffix: '', }, @@ -2256,8 +2251,7 @@ export module Mock { scheme: 'lndconnect', preferredExternalPort: 10009, addSsl: null, - secure: true, - ssl: true, + secure: { ssl: true }, }, suffix: 'cert=askjdfbjadnaskjnd&macaroon=ksjbdfnhjasbndjksand', }, @@ -2325,8 +2319,7 @@ export module Mock { scheme: null, preferredExternalPort: 9735, addSsl: null, - secure: true, - ssl: true, + secure: { ssl: true }, }, suffix: '', }, diff --git a/web/projects/ui/src/app/services/api/mock-patch.ts b/web/projects/ui/src/app/services/api/mock-patch.ts index a34a91652..c861dbb62 100644 --- a/web/projects/ui/src/app/services/api/mock-patch.ts +++ b/web/projects/ui/src/app/services/api/mock-patch.ts @@ -414,8 +414,7 @@ export const mockPatchData: DataModel = { preferredExternalPort: 443, scheme: 'https', }, - secure: true, - ssl: true, + secure: { ssl: true }, }, suffix: '', }, @@ -661,8 +660,7 @@ export const mockPatchData: DataModel = { scheme: 'grpc', preferredExternalPort: 10009, addSsl: null, - secure: true, - ssl: true, + secure: { ssl: true }, }, suffix: '', }, @@ -730,8 +728,7 @@ export const mockPatchData: DataModel = { scheme: 'lndconnect', preferredExternalPort: 10009, addSsl: null, - secure: true, - ssl: true, + secure: { ssl: true }, }, suffix: 'cert=askjdfbjadnaskjnd&macaroon=ksjbdfnhjasbndjksand', }, @@ -799,8 +796,7 @@ export const mockPatchData: DataModel = { scheme: null, preferredExternalPort: 9735, addSsl: null, - secure: true, - ssl: true, + secure: { ssl: true }, }, suffix: '', },