mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 14:29:45 +00:00
Feature/callbacks (#2678)
* wip * initialize callbacks * wip * smtp * list_service_interfaces * wip * wip * fix domains * fix hostname handling in NetService * misc fixes * getInstalledPackages * misc fixes * publish v6 lib * refactor service effects * fix import * fix container runtime * fix tests * apply suggestions from review
This commit is contained in:
47
sdk/lib/util/GetSslCertificate.ts
Normal file
47
sdk/lib/util/GetSslCertificate.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { T } from ".."
|
||||
import { Effects } from "../types"
|
||||
|
||||
export class GetSslCertificate {
|
||||
constructor(
|
||||
readonly effects: Effects,
|
||||
readonly hostnames: string[],
|
||||
readonly algorithm?: T.Algorithm,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Returns the system SMTP credentials. Restarts the service if the credentials change
|
||||
*/
|
||||
const() {
|
||||
return this.effects.getSslCertificate({
|
||||
hostnames: this.hostnames,
|
||||
algorithm: this.algorithm,
|
||||
callback: this.effects.restart,
|
||||
})
|
||||
}
|
||||
/**
|
||||
* Returns the system SMTP credentials. Does nothing if the credentials change
|
||||
*/
|
||||
once() {
|
||||
return this.effects.getSslCertificate({
|
||||
hostnames: this.hostnames,
|
||||
algorithm: this.algorithm,
|
||||
})
|
||||
}
|
||||
/**
|
||||
* Watches the system SMTP credentials. Takes a custom callback function to run whenever the credentials change
|
||||
*/
|
||||
async *watch() {
|
||||
while (true) {
|
||||
let callback: () => void
|
||||
const waitForNext = new Promise<void>((resolve) => {
|
||||
callback = resolve
|
||||
})
|
||||
yield await this.effects.getSslCertificate({
|
||||
hostnames: this.hostnames,
|
||||
algorithm: this.algorithm,
|
||||
callback: () => callback(),
|
||||
})
|
||||
await waitForNext
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,7 @@ export class GetSystemSmtp {
|
||||
* Returns the system SMTP credentials. Does nothing if the credentials change
|
||||
*/
|
||||
once() {
|
||||
return this.effects.getSystemSmtp({
|
||||
callback: () => {},
|
||||
})
|
||||
return this.effects.getSystemSmtp({})
|
||||
}
|
||||
/**
|
||||
* Watches the system SMTP credentials. Takes a custom callback function to run whenever the credentials change
|
||||
|
||||
@@ -55,9 +55,9 @@ export type ServiceInterfaceFilled = {
|
||||
/** Whether or not to mask the URIs for this interface. Useful if the URIs contain sensitive information, such as a password, macaroon, or API key */
|
||||
masked: boolean
|
||||
/** Information about the host for this binding */
|
||||
host: Host
|
||||
host: Host | null
|
||||
/** URI information */
|
||||
addressInfo: FilledAddressInfo
|
||||
addressInfo: FilledAddressInfo | null
|
||||
/** Indicates if we are a ui/p2p/api for the kind of interface that this is representing */
|
||||
type: ServiceInterfaceType
|
||||
/** The primary hostname for the service, as chosen by the user */
|
||||
@@ -183,33 +183,36 @@ const makeInterfaceFilled = async ({
|
||||
}: {
|
||||
effects: Effects
|
||||
id: string
|
||||
packageId: string | null
|
||||
callback: () => void
|
||||
packageId?: string
|
||||
callback?: () => void
|
||||
}) => {
|
||||
const serviceInterfaceValue = await effects.getServiceInterface({
|
||||
serviceInterfaceId: id,
|
||||
packageId,
|
||||
callback,
|
||||
})
|
||||
if (!serviceInterfaceValue) {
|
||||
return null
|
||||
}
|
||||
const hostId = serviceInterfaceValue.addressInfo.hostId
|
||||
const host = await effects.getHostInfo({
|
||||
packageId,
|
||||
hostId,
|
||||
callback,
|
||||
})
|
||||
const primaryUrl = await effects
|
||||
.getPrimaryUrl({
|
||||
serviceInterfaceId: id,
|
||||
packageId,
|
||||
callback,
|
||||
})
|
||||
.catch((e) => null)
|
||||
const primaryUrl = await effects.getPrimaryUrl({
|
||||
hostId,
|
||||
packageId,
|
||||
callback,
|
||||
})
|
||||
|
||||
const interfaceFilled: ServiceInterfaceFilled = {
|
||||
...serviceInterfaceValue,
|
||||
primaryUrl: primaryUrl,
|
||||
host,
|
||||
addressInfo: filledAddress(host, serviceInterfaceValue.addressInfo),
|
||||
addressInfo: host
|
||||
? filledAddress(host, serviceInterfaceValue.addressInfo)
|
||||
: null,
|
||||
get primaryHostname() {
|
||||
if (primaryUrl == null) return null
|
||||
return getHostname(primaryUrl)
|
||||
@@ -221,7 +224,7 @@ const makeInterfaceFilled = async ({
|
||||
export class GetServiceInterface {
|
||||
constructor(
|
||||
readonly effects: Effects,
|
||||
readonly opts: { id: string; packageId: string | null },
|
||||
readonly opts: { id: string; packageId?: string },
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -230,7 +233,7 @@ export class GetServiceInterface {
|
||||
async const() {
|
||||
const { id, packageId } = this.opts
|
||||
const callback = this.effects.restart
|
||||
const interfaceFilled: ServiceInterfaceFilled = await makeInterfaceFilled({
|
||||
const interfaceFilled = await makeInterfaceFilled({
|
||||
effects: this.effects,
|
||||
id,
|
||||
packageId,
|
||||
@@ -244,12 +247,10 @@ export class GetServiceInterface {
|
||||
*/
|
||||
async once() {
|
||||
const { id, packageId } = this.opts
|
||||
const callback = () => {}
|
||||
const interfaceFilled: ServiceInterfaceFilled = await makeInterfaceFilled({
|
||||
const interfaceFilled = await makeInterfaceFilled({
|
||||
effects: this.effects,
|
||||
id,
|
||||
packageId,
|
||||
callback,
|
||||
})
|
||||
|
||||
return interfaceFilled
|
||||
@@ -277,7 +278,7 @@ export class GetServiceInterface {
|
||||
}
|
||||
export function getServiceInterface(
|
||||
effects: Effects,
|
||||
opts: { id: string; packageId: string | null },
|
||||
opts: { id: string; packageId?: string },
|
||||
) {
|
||||
return new GetServiceInterface(effects, opts)
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ const makeManyInterfaceFilled = async ({
|
||||
callback,
|
||||
}: {
|
||||
effects: Effects
|
||||
packageId: string | null
|
||||
callback: () => void
|
||||
packageId?: string
|
||||
callback?: () => void
|
||||
}) => {
|
||||
const serviceInterfaceValues = await effects.listServiceInterfaces({
|
||||
packageId,
|
||||
@@ -27,9 +27,12 @@ const makeManyInterfaceFilled = async ({
|
||||
hostId,
|
||||
callback,
|
||||
})
|
||||
if (!host) {
|
||||
throw new Error(`host ${hostId} not found!`)
|
||||
}
|
||||
const primaryUrl = await effects
|
||||
.getPrimaryUrl({
|
||||
serviceInterfaceId: serviceInterfaceValue.id,
|
||||
hostId,
|
||||
packageId,
|
||||
callback,
|
||||
})
|
||||
@@ -52,7 +55,7 @@ const makeManyInterfaceFilled = async ({
|
||||
export class GetServiceInterfaces {
|
||||
constructor(
|
||||
readonly effects: Effects,
|
||||
readonly opts: { packageId: string | null },
|
||||
readonly opts: { packageId?: string },
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -75,12 +78,10 @@ export class GetServiceInterfaces {
|
||||
*/
|
||||
async once() {
|
||||
const { packageId } = this.opts
|
||||
const callback = () => {}
|
||||
const interfaceFilled: ServiceInterfaceFilled[] =
|
||||
await makeManyInterfaceFilled({
|
||||
effects: this.effects,
|
||||
packageId,
|
||||
callback,
|
||||
})
|
||||
|
||||
return interfaceFilled
|
||||
@@ -107,7 +108,7 @@ export class GetServiceInterfaces {
|
||||
}
|
||||
export function getServiceInterfaces(
|
||||
effects: Effects,
|
||||
opts: { packageId: string | null },
|
||||
opts: { packageId?: string },
|
||||
) {
|
||||
return new GetServiceInterfaces(effects, opts)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user