Skip to content

Commit

Permalink
Merge branch 'integration/new-container-runtime' of github.com:Start9…
Browse files Browse the repository at this point in the history
…Labs/start-os into integration/new-container-runtime
  • Loading branch information
Blu-J committed Feb 23, 2024
2 parents 4e3075a + 87d6684 commit 50f0ead
Show file tree
Hide file tree
Showing 25 changed files with 1,096 additions and 571 deletions.
2 changes: 0 additions & 2 deletions sdk/lib/util/getServiceInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import {
HostInfo,
Hostname,
HostnameInfo,
ServiceInterface,
} from "../types"
import * as regexes from "./regexes"
import { ServiceInterfaceType } from "./utils"

export type UrlString = string
Expand Down
1 change: 1 addition & 0 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/projects/shared/src/types/workspace-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type WorkspaceConfig = {
community: 'https://community-registry.start9.com/'
}
mocks: {
maskAs: 'tor' | 'local' | 'localhost'
maskAs: 'tor' | 'local' | 'ip' | 'localhost'
// enables local development in secure mode
maskAsHttps: boolean
skipStartupAlerts: boolean
Expand Down
6 changes: 0 additions & 6 deletions web/projects/ui/src/app/app/menu/menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@
<ion-label class="label montserrat" routerLinkActive="label_selected">
{{ page.title }}
</ion-label>
<ion-icon
*ngIf="page.url === '/system' && (warning$ | async)"
color="warning"
size="small"
name="warning"
></ion-icon>
<ion-icon
*ngIf="page.url === '/system' && (showEOSUpdate$ | async)"
color="success"
Expand Down
5 changes: 0 additions & 5 deletions web/projects/ui/src/app/app/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ export class MenuComponent {

readonly theme$ = inject(THEME)

readonly warning$ = merge(
of(this.config.isTorHttp()),
this.patch.watch$('server-info', 'ntp-synced').pipe(map(synced => !synced)),
)

constructor(
private readonly patch: PatchDB<DataModel>,
private readonly eosService: EOSService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@
>
{{ (connected$ | async) ? rendering.display : 'Unknown' }}

<span
*ngIf="
rendering.display === PR[PS.Stopping].display &&
(sigtermTimeout | durationToSeconds) > 30
"
>
this may take a while
<span *ngIf="sigtermTimeout && (sigtermTimeout | durationToSeconds) > 30">
. This may take a while
</span>

<span *ngIf="installProgress">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,72 +1,44 @@
<ion-item *ngIf="interface">
<ion-item *ngIf="iFace">
<ion-icon
slot="start"
size="large"
[name]="interface.def.ui ? 'desktop-outline' : 'terminal-outline'"
[name]="
iFace.type === 'ui'
? 'desktop-outline'
: iFace.type === 'api'
? 'terminal-outline'
: 'people-outline'
"
></ion-icon>
<ion-label>
<h1>{{ interface.def.name }}</h1>
<h2>{{ interface.def.description }}</h2>
<h1>{{ iFace.name }}</h1>
<h2>{{ iFace.description }}</h2>
</ion-label>
</ion-item>
<div *ngIf="interface" style="padding-left: 64px">
<!-- has tor -->
<ion-item *ngIf="interface.addresses['tor-address'] as tor">
<div *ngIf="iFace" style="padding-left: 64px">
<ion-item *ngFor="let address of iFace.addresses">
<ion-label>
<h2>Tor Address</h2>
<p>{{ tor }}</p>
<h2>{{ address.name }}</h2>
<p>{{ address.url }}</p>
</ion-label>
<ion-buttons slot="end">
<ion-button *ngIf="interface.def.ui" fill="clear" (click)="launch(tor)">
<ion-button
*ngIf="iFace.type === 'ui'"
fill="clear"
(click)="launch(address.url)"
>
<ion-icon size="small" slot="icon-only" name="open-outline"></ion-icon>
</ion-button>
<ion-button fill="clear" (click)="showQR(tor)">
<ion-button fill="clear" (click)="showQR(address.url)">
<ion-icon
size="small"
slot="icon-only"
name="qr-code-outline"
></ion-icon>
</ion-button>
<ion-button fill="clear" (click)="copy(tor)">
<ion-button fill="clear" (click)="copy(address.url)">
<ion-icon size="small" slot="icon-only" name="copy-outline"></ion-icon>
</ion-button>
</ion-buttons>
</ion-item>
<!-- no tor -->
<ion-item *ngIf="!interface.addresses['tor-address']">
<ion-label>
<h2>Tor Address</h2>
<p>Service does not use a Tor Address</p>
</ion-label>
</ion-item>

<!-- lan -->
<ion-item *ngIf="interface.addresses['lan-address'] as lan">
<ion-label>
<h2>LAN Address</h2>
<p>{{ lan }}</p>
</ion-label>
<ion-buttons slot="end">
<ion-button *ngIf="interface.def.ui" fill="clear" (click)="launch(lan)">
<ion-icon size="small" slot="icon-only" name="open-outline"></ion-icon>
</ion-button>
<ion-button fill="clear" (click)="showQR(lan)">
<ion-icon
size="small"
slot="icon-only"
name="qr-code-outline"
></ion-icon>
</ion-button>
<ion-button fill="clear" (click)="copy(lan)">
<ion-icon size="small" slot="icon-only" name="copy-outline"></ion-icon>
</ion-button>
</ion-buttons>
</ion-item>
<!-- no lan -->
<ion-item *ngIf="!interface.addresses['lan-address']">
<ion-label>
<h2>LAN Address</h2>
<p>N/A</p>
</ion-label>
</ion-item>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,29 @@
</ion-header>

<ion-content class="ion-padding-top with-widgets">
<ion-item-group>
<!-- iff ui -->
<ng-container *ngIf="ui">
<ion-item-divider>User Interface</ion-item-divider>
<app-interfaces-item [interface]="ui"></app-interfaces-item>
<ion-item-group *ngIf="serviceInterfaces$ | async as serviceInterfaces">
<ng-container *ngIf="serviceInterfaces.ui.length">
<ion-item-divider>User Interfaces (UI)</ion-item-divider>
<app-interfaces-item
*ngFor="let ui of serviceInterfaces.ui"
[iFace]="ui"
></app-interfaces-item>
</ng-container>

<!-- other interface -->
<ng-container *ngIf="other.length">
<ion-item-divider>Machine Interfaces</ion-item-divider>
<div *ngFor="let interface of other" style="margin-bottom: 30px">
<app-interfaces-item [interface]="interface"></app-interfaces-item>
</div>
<ng-container *ngIf="serviceInterfaces.api.length">
<ion-item-divider>Application Program Interfaces (API)</ion-item-divider>
<app-interfaces-item
*ngFor="let api of serviceInterfaces.api"
[iFace]="api"
></app-interfaces-item>
</ng-container>

<ng-container *ngIf="serviceInterfaces.p2p.length">
<ion-item-divider>Peer-To-Peer Interfaces (P2P)</ion-item-divider>
<app-interfaces-item
*ngFor="let p2p of serviceInterfaces.p2p"
[iFace]="p2p"
></app-interfaces-item>
</ng-container>
</ion-item-group>
</ion-content>
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import { WINDOW } from '@ng-web-apis/common'
import { ActivatedRoute } from '@angular/router'
import { ModalController, ToastController } from '@ionic/angular'
import { copyToClipboard, getPkgId } from '@start9labs/shared'
import { getUiInterfaceKey } from 'src/app/services/config.service'
import {
DataModel,
InstalledPackageDataEntry,
InterfaceDef,
} from 'src/app/services/patch-db/data-model'
import { DataModel } from 'src/app/services/patch-db/data-model'
import { PatchDB } from 'patch-db-client'
import { QRComponent } from 'src/app/components/qr/qr.component'
import { getPackage } from '../../../util/get-package-data'
import { map } from 'rxjs'
import {
ServiceInterface,
ServiceInterfaceWithHostInfo,
} from '@start9labs/start-sdk/mjs/lib/types'

interface LocalInterface {
def: InterfaceDef
addresses: InstalledPackageDataEntry['interface-addresses'][string]
type MappedInterface = ServiceInterface & {
addresses: MappedAddress[]
}
type MappedAddress = {
name: string
url: string
}

@Component({
Expand All @@ -24,60 +26,33 @@ interface LocalInterface {
styleUrls: ['./app-interfaces.page.scss'],
})
export class AppInterfacesPage {
ui?: LocalInterface
other: LocalInterface[] = []
readonly pkgId = getPkgId(this.route)

readonly serviceInterfaces$ = this.patch
.watch$('package-data', this.pkgId, 'installed', 'service-interfaces')
.pipe(
map(interfaces => {
const sorted = Object.values(interfaces)
.sort(iface =>
iface.name.toLowerCase() > iface.name.toLowerCase() ? -1 : 1,
)
.map(iface => ({
...iface,
addresses: getAddresses(iface),
}))

return {
ui: sorted.filter(val => val.type === 'ui'),
api: sorted.filter(val => val.type === 'api'),
p2p: sorted.filter(val => val.type === 'p2p'),
}
}),
)

constructor(
private readonly route: ActivatedRoute,
private readonly patch: PatchDB<DataModel>,
) {}

async ngOnInit() {
const pkg = await getPackage(this.patch, this.pkgId)
if (!pkg) return

const interfaces = pkg.manifest.interfaces
const uiKey = getUiInterfaceKey(interfaces)

if (!pkg.installed) return

const addressesMap = pkg.installed['interface-addresses']

if (uiKey) {
const uiAddresses = addressesMap[uiKey]
this.ui = {
def: interfaces[uiKey],
addresses: {
'lan-address': uiAddresses['lan-address']
? 'https://' + uiAddresses['lan-address']
: '',
// leave http for services
'tor-address': uiAddresses['tor-address']
? 'http://' + uiAddresses['tor-address']
: '',
},
}
}

this.other = Object.keys(interfaces)
.filter(key => key !== uiKey)
.map(key => {
const addresses = addressesMap[key]
return {
def: interfaces[key],
addresses: {
'lan-address': addresses['lan-address']
? 'https://' + addresses['lan-address']
: '',
'tor-address': addresses['tor-address']
? // leave http for services
'http://' + addresses['tor-address']
: '',
},
}
})
}
}

@Component({
Expand All @@ -86,8 +61,7 @@ export class AppInterfacesPage {
styleUrls: ['./app-interfaces.page.scss'],
})
export class AppInterfacesItemComponent {
@Input()
interface!: LocalInterface
@Input() iFace!: MappedInterface

constructor(
private readonly toastCtrl: ToastController,
Expand Down Expand Up @@ -126,3 +100,65 @@ export class AppInterfacesItemComponent {
await toast.present()
}
}

function getAddresses(
serviceInterface: ServiceInterfaceWithHostInfo,
): MappedAddress[] {
const host = serviceInterface.hostInfo
const addressInfo = serviceInterface.addressInfo
const username = addressInfo.username ? addressInfo.username + '@' : ''
const suffix = addressInfo.suffix || ''

const hostnames =
host.kind === 'multi'
? host.hostnames
: host.hostname
? [host.hostname]
: []

return hostnames
.map(h => {
const addresses: MappedAddress[] = []

let name = ''
let hostname = ''

if (h.kind === 'onion') {
name = 'Tor'
hostname = h.hostname.value
} else {
name = h.hostname.kind
hostname =
h.hostname.kind === 'domain'
? `${h.hostname.subdomain}.${h.hostname.domain}`
: h.hostname.value
}

if (h.hostname.sslPort) {
const port = h.hostname.sslPort === 443 ? '' : `:${h.hostname.sslPort}`
const scheme = addressInfo.bindOptions.addSsl?.scheme
? `${addressInfo.bindOptions.addSsl.scheme}://`
: ''

addresses.push({
name,
url: `${scheme}${username}${hostname}${port}${suffix}`,
})
}

if (h.hostname.port) {
const port = h.hostname.port === 80 ? '' : `:${h.hostname.port}`
const scheme = addressInfo.bindOptions.scheme
? `${addressInfo.bindOptions.scheme}://`
: ''

addresses.push({
name,
url: `${scheme}${username}${hostname}${port}${suffix}`,
})
}

return addresses
})
.flat()
}
Loading

0 comments on commit 50f0ead

Please sign in to comment.