Skip to content

Commit

Permalink
make service interfaces and hosts one to one
Browse files Browse the repository at this point in the history
  • Loading branch information
MattDHill committed Feb 19, 2024
1 parent eae75c1 commit d7bc7a2
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 308 deletions.
16 changes: 8 additions & 8 deletions container-runtime/src/Adapters/HostSystemStartOs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ export class HostSystemStartOs implements Effects {
T.Effects["clearBindings"]
>
}
clearNetworkInterfaces(
...[]: Parameters<T.Effects["clearNetworkInterfaces"]>
clearServiceInterfaces(
...[]: Parameters<T.Effects["clearServiceInterfaces"]>
) {
return this.rpcRound("clearNetworkInterfaces", null) as ReturnType<
T.Effects["clearNetworkInterfaces"]
return this.rpcRound("clearServiceInterfaces", null) as ReturnType<
T.Effects["clearServiceInterfaces"]
>
}
createOverlayedImage(options: { imageId: string }): Promise<string> {
Expand All @@ -131,11 +131,11 @@ export class HostSystemStartOs implements Effects {
T.Effects["exportAction"]
>
}
exportNetworkInterface(
...[options]: Parameters<T.Effects["exportNetworkInterface"]>
exportServiceInterface(
...[options]: Parameters<T.Effects["exportServiceInterface"]>
) {
return this.rpcRound("exportNetworkInterface", options) as ReturnType<
T.Effects["exportNetworkInterface"]
return this.rpcRound("exportServiceInterface", options) as ReturnType<
T.Effects["exportServiceInterface"]
>
}
exposeForDependents(...[options]: any) {
Expand Down
4 changes: 2 additions & 2 deletions core/startos/src/service/service_effect_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ pub fn service_effect_handler() -> ParentHandler {
// .subcommand("removeAddress",from_fn(remove_address))
// .subcommand("exportAction",from_fn(export_action))
// .subcommand("bind",from_fn(bind))
// .subcommand("clearNetworkInterfaces",from_fn(clear_network_interfaces))
// .subcommand("exportNetworkInterface",from_fn(export_network_interface))
// .subcommand("clearServiceInterfaces",from_fn(clear_network_interfaces))
// .subcommand("exportServiceInterface",from_fn(export_network_interface))
// .subcommand("clearBindings",from_fn(clear_bindings))
// .subcommand("getHostnames",from_fn(get_hostnames))
// .subcommand("getInterface",from_fn(get_interface))
Expand Down
2 changes: 1 addition & 1 deletion sdk/lib/config/setupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function setupConfig<
return { error: "Set config type error for config" }
}
await effects.clearBindings()
await effects.clearNetworkInterfaces()
await effects.clearServiceInterfaces()
const { restart } = await write({
input: JSON.parse(JSON.stringify(input)),
effects,
Expand Down
4 changes: 2 additions & 2 deletions sdk/lib/interfaces/Host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type AddSslOptions = {
addXForwardedHeaders?: boolean /** default: false */
}
type Security = { secure: false; ssl: false } | { secure: true; ssl: boolean }
export type PortOptions = {
export type BindOptions = {
scheme: Scheme
preferredExternalPort: number
addSsl: AddSslOptions | null
Expand Down Expand Up @@ -85,7 +85,7 @@ type PortOptionsByKnownProtocol =
scheme?: Scheme
addSsl?: AddSslOptions | null
}
type PortOptionsByProtocol = PortOptionsByKnownProtocol | PortOptions
type PortOptionsByProtocol = PortOptionsByKnownProtocol | BindOptions

export type HostKind = "static" | "single" | "multi"

Expand Down
8 changes: 4 additions & 4 deletions sdk/lib/interfaces/Origin.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Address } from "../types"
import { Host, PortOptions } from "./Host"
import { AddressInfo } from "../types"
import { Host, BindOptions } from "./Host"

export class Origin<T extends Host> {
constructor(
readonly host: T,
readonly options: PortOptions,
readonly options: BindOptions,
) {}

build({ username, path, search }: BuildOptions): Address {
build({ username, path, search }: BuildOptions): AddressInfo {
const qpEntries = Object.entries(search)
.map(
([key, val]) => `${encodeURIComponent(key)}=${encodeURIComponent(val)}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address, Effects } from "../types"
import { NetworkInterfaceType } from "../util/utils"
import { AddressInfo, Effects } from "../types"
import { ServiceInterfaceType } from "../util/utils"
import { AddressReceipt } from "./AddressReceipt"
import { Host } from "./Host"
import { Origin } from "./Origin"
Expand All @@ -15,7 +15,7 @@ import { Origin } from "./Origin"
* @param options
* @returns
*/
export class NetworkInterfaceBuilder {
export class ServiceInterfaceBuilder {
constructor(
readonly options: {
effects: Effects
Expand All @@ -24,7 +24,7 @@ export class NetworkInterfaceBuilder {
description: string
hasPrimary: boolean
disabled: boolean
type: NetworkInterfaceType
type: ServiceInterfaceType
username: null | string
path: string
search: Record<string, string>
Expand All @@ -36,12 +36,12 @@ export class NetworkInterfaceBuilder {
*
* The returned addressReceipt serves as proof that the addresses were registered
*
* @param addresses
* @param addressInfo
* @returns
*/
async export<Origins extends Origin<Host>[]>(
origins: Origins,
): Promise<Address[] & AddressReceipt> {
async export<OriginForHost extends Origin<Host>>(
origin: OriginForHost,
): Promise<AddressInfo & AddressReceipt> {
const {
name,
description,
Expand All @@ -54,20 +54,18 @@ export class NetworkInterfaceBuilder {
search,
} = this.options

const addresses = Array.from(origins).map((o) =>
o.build({ username, path, search, scheme: null }),
)
const addressInfo = origin.build({ username, path, search, scheme: null })

await this.options.effects.exportNetworkInterface({
interfaceId: id,
await this.options.effects.exportServiceInterface({
id,
name,
description,
hasPrimary,
disabled,
addresses,
addressInfo,
type,
})

return addresses as Address[] & AddressReceipt
return addressInfo as AddressInfo & AddressReceipt
}
}
4 changes: 2 additions & 2 deletions sdk/lib/interfaces/setupInterfaces.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Config } from "../config/builder/config"
import { SDKManifest } from "../manifest/ManifestTypes"
import { Address, Effects } from "../types"
import { AddressInfo, Effects } from "../types"
import { Utils } from "../util/utils"
import { AddressReceipt } from "./AddressReceipt"

export type InterfacesReceipt = Array<Address[] & AddressReceipt>
export type InterfacesReceipt = Array<AddressInfo[] & AddressReceipt>
export type SetInterfaces<
Manifest extends SDKManifest,
Store,
Expand Down
2 changes: 1 addition & 1 deletion sdk/lib/mainFn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Effects, ExpectedExports } from "../types"
import { createMainUtils } from "../util"
import { Utils, createUtils } from "../util/utils"
import { Daemons } from "./Daemons"
import "../interfaces/NetworkInterfaceBuilder"
import "../interfaces/ServiceInterfaceBuilder"
import "../interfaces/Origin"

import "./Daemons"
Expand Down
4 changes: 2 additions & 2 deletions sdk/lib/test/host.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NetworkInterfaceBuilder } from "../interfaces/NetworkInterfaceBuilder"
import { ServiceInterfaceBuilder } from "../interfaces/ServiceInterfaceBuilder"
import { Effects } from "../types"
import { createUtils } from "../util"

Expand All @@ -8,7 +8,7 @@ describe("host", () => {
const utils = createUtils<never, never>(effects)
const foo = utils.host.multi("foo")
const fooOrigin = await foo.bindPort(80, { protocol: "http" as const })
const fooInterface = new NetworkInterfaceBuilder({
const fooInterface = new ServiceInterfaceBuilder({
effects,
name: "Foo",
id: "foo",
Expand Down
2 changes: 1 addition & 1 deletion sdk/lib/test/util.getNetworkInterface.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getHostname } from "../util/getNetworkInterface"
import { getHostname } from "../util/getServiceInterface"

describe("getHostname ", () => {
const inputToExpected = [
Expand Down
2 changes: 1 addition & 1 deletion sdk/lib/test/utils.splitCommand.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getHostname } from "../util/getNetworkInterface"
import { getHostname } from "../util/getServiceInterface"
import { splitCommand } from "../util/splitCommand"

describe("splitCommand ", () => {
Expand Down
Loading

0 comments on commit d7bc7a2

Please sign in to comment.