mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
make service interfaces and hosts one to one
This commit is contained in:
71
sdk/lib/interfaces/ServiceInterfaceBuilder.ts
Normal file
71
sdk/lib/interfaces/ServiceInterfaceBuilder.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { AddressInfo, Effects } from "../types"
|
||||
import { ServiceInterfaceType } from "../util/utils"
|
||||
import { AddressReceipt } from "./AddressReceipt"
|
||||
import { Host } from "./Host"
|
||||
import { Origin } from "./Origin"
|
||||
|
||||
/**
|
||||
* A helper class for creating a Network Interface
|
||||
*
|
||||
* Network Interfaces are collections of web addresses that expose the same API or other resource,
|
||||
* display to the user with under a common name and description.
|
||||
*
|
||||
* All URIs on an interface inherit the same ui: bool, basic auth credentials, path, and search (query) params
|
||||
*
|
||||
* @param options
|
||||
* @returns
|
||||
*/
|
||||
export class ServiceInterfaceBuilder {
|
||||
constructor(
|
||||
readonly options: {
|
||||
effects: Effects
|
||||
name: string
|
||||
id: string
|
||||
description: string
|
||||
hasPrimary: boolean
|
||||
disabled: boolean
|
||||
type: ServiceInterfaceType
|
||||
username: null | string
|
||||
path: string
|
||||
search: Record<string, string>
|
||||
},
|
||||
) {}
|
||||
|
||||
/**
|
||||
* A function to register a group of origins (<PROTOCOL> :// <HOSTNAME> : <PORT>) with StartOS
|
||||
*
|
||||
* The returned addressReceipt serves as proof that the addresses were registered
|
||||
*
|
||||
* @param addressInfo
|
||||
* @returns
|
||||
*/
|
||||
async export<OriginForHost extends Origin<Host>>(
|
||||
origin: OriginForHost,
|
||||
): Promise<AddressInfo & AddressReceipt> {
|
||||
const {
|
||||
name,
|
||||
description,
|
||||
hasPrimary,
|
||||
disabled,
|
||||
id,
|
||||
type,
|
||||
username,
|
||||
path,
|
||||
search,
|
||||
} = this.options
|
||||
|
||||
const addressInfo = origin.build({ username, path, search, scheme: null })
|
||||
|
||||
await this.options.effects.exportServiceInterface({
|
||||
id,
|
||||
name,
|
||||
description,
|
||||
hasPrimary,
|
||||
disabled,
|
||||
addressInfo,
|
||||
type,
|
||||
})
|
||||
|
||||
return addressInfo as AddressInfo & AddressReceipt
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user