Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bonez committed Nov 29, 2024
1 parent def6699 commit 821460e
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 54 deletions.
1 change: 1 addition & 0 deletions core/startos/src/db/model/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub struct ServerInfo {
#[ts(type = "string")]
pub tor_address: Url,
#[ts(as = "BTreeMap::<String, NetworkInterfaceInfo>")]
#[serde(default)]
pub network_interfaces: BTreeMap<InternedString, NetworkInterfaceInfo>,
pub acme: Option<AcmeSettings>,
#[serde(default)]
Expand Down
1 change: 0 additions & 1 deletion core/startos/src/registry/package/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ pub struct PackageVersionInfo {
pub icon: DataUrl<'static>,
pub description: Description,
pub release_notes: String,
#[ts(type = "string")]
pub git_hash: GitHash,
#[ts(type = "string")]
pub license: InternedString,
Expand Down
29 changes: 28 additions & 1 deletion core/startos/src/s9pk/git_hash.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::path::Path;

use tokio::process::Command;
use ts_rs::TS;

use crate::prelude::*;
use crate::util::Invoke;

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, TS)]
#[ts(type = "string")]
pub struct GitHash(String);

impl GitHash {
Expand All @@ -31,6 +33,31 @@ impl GitHash {
}
Ok(GitHash(hash))
}
pub fn load_sync() -> Option<GitHash> {
let mut hash = String::from_utf8(
std::process::Command::new("git")
.arg("rev-parse")
.arg("HEAD")
.output()
.ok()?
.stdout,
)
.ok()?;
if !std::process::Command::new("git")
.arg("diff-index")
.arg("--quiet")
.arg("HEAD")
.arg("--")
.output()
.ok()?
.status
.success()
{
hash += "-modified";
}

Some(GitHash(hash))
}
}

impl AsRef<str> for GitHash {
Expand Down
4 changes: 2 additions & 2 deletions core/startos/src/s9pk/v2/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ pub struct Manifest {
pub dependencies: Dependencies,
#[serde(default)]
pub hardware_requirements: HardwareRequirements,
#[serde(default)]
#[ts(type = "string | null")]
#[ts(optional)]
#[serde(default = "GitHash::load_sync")]
pub git_hash: Option<GitHash>,
#[serde(default = "current_version")]
#[ts(type = "string")]
Expand Down
5 changes: 2 additions & 3 deletions sdk/base/lib/Effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import {
SetHealth,
BindParams,
HostId,
LanInfo,
NetInfo,
Host,
ExportServiceInterfaceParams,
ServiceInterface,
ActionRequest,
RequestActionParams,
MainStatus,
} from "./osBindings"
Expand Down Expand Up @@ -118,7 +117,7 @@ export type Effects = {
packageId?: PackageId
hostId: HostId
internalPort: number
}): Promise<LanInfo>
}): Promise<NetInfo>
/** Removes all network bindings, called in the setupInputSpec */
clearBindings(options: {
except: { id: HostId; internalPort: number }[]
Expand Down
3 changes: 3 additions & 0 deletions sdk/base/lib/osBindings/GitHash.ts
Original file line number Diff line number Diff line change
@@ -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 GitHash = string
7 changes: 1 addition & 6 deletions sdk/base/lib/osBindings/IpInfo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type IpInfo = {
ipv4Range: string | null
ipv4: string | null
ipv6Range: string | null
ipv6: string | null
}
export type IpInfo = string[]
3 changes: 2 additions & 1 deletion sdk/base/lib/osBindings/Manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { Alerts } from "./Alerts"
import type { Dependencies } from "./Dependencies"
import type { Description } from "./Description"
import type { GitHash } from "./GitHash"
import type { HardwareRequirements } from "./HardwareRequirements"
import type { ImageConfig } from "./ImageConfig"
import type { ImageId } from "./ImageId"
Expand Down Expand Up @@ -30,6 +31,6 @@ export type Manifest = {
alerts: Alerts
dependencies: Dependencies
hardwareRequirements: HardwareRequirements
gitHash: string | null
gitHash?: GitHash
osVersion: string
}
3 changes: 2 additions & 1 deletion sdk/base/lib/osBindings/PackageVersionInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Alerts } from "./Alerts"
import type { DataUrl } from "./DataUrl"
import type { DependencyMetadata } from "./DependencyMetadata"
import type { Description } from "./Description"
import type { GitHash } from "./GitHash"
import type { HardwareRequirements } from "./HardwareRequirements"
import type { MerkleArchiveCommitment } from "./MerkleArchiveCommitment"
import type { PackageId } from "./PackageId"
Expand All @@ -13,7 +14,7 @@ export type PackageVersionInfo = {
icon: DataUrl
description: Description
releaseNotes: string
gitHash: string
gitHash: GitHash
license: string
wrapperRepo: string
upstreamRepo: string
Expand Down
1 change: 1 addition & 0 deletions sdk/base/lib/osBindings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export { GetSslKeyParams } from "./GetSslKeyParams"
export { GetStatusParams } from "./GetStatusParams"
export { GetStoreParams } from "./GetStoreParams"
export { GetSystemSmtpParams } from "./GetSystemSmtpParams"
export { GitHash } from "./GitHash"
export { Governor } from "./Governor"
export { Guid } from "./Guid"
export { HardwareRequirements } from "./HardwareRequirements"
Expand Down
11 changes: 0 additions & 11 deletions sdk/package/lib/manifest/setupManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ export function setupManifest<
return manifest
}

function gitHash(): string {
const hash = execSync("git rev-parse HEAD").toString().trim()
try {
execSync("git diff-index --quiet HEAD --")
return hash
} catch (e) {
return hash + "-modified"
}
}

export function buildManifest<
Id extends string,
Version extends string,
Expand Down Expand Up @@ -67,7 +57,6 @@ export function buildManifest<
)
return {
...manifest,
gitHash: gitHash(),
osVersion: SDKVersion,
version: versions.current.options.version,
releaseNotes: versions.current.options.releaseNotes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,18 @@ <h2>LAN</h2>
<ion-icon slot="icon-only" name="copy-outline"></ion-icon>
</ion-button>
</ion-item>
<ng-container *ngFor="let iface of server.ipInfo| keyvalue">
<ion-item *tuiLet="iface.value.ipv4 as ipv4">
<ion-label>
<h2>{{ iface.key }} (IPv4)</h2>
<p>{{ ipv4 || 'n/a' }}</p>
</ion-label>
<ion-button *ngIf="ipv4" slot="end" fill="clear" (click)="copy(ipv4)">
<ion-icon slot="icon-only" name="copy-outline"></ion-icon>
</ion-button>
</ion-item>
<ion-item *tuiLet="iface.value.ipv6 as ipv6">
<ion-label>
<h2>{{ iface.key }} (IPv6)</h2>
<p>{{ ipv6 || 'n/a' }}</p>
</ion-label>
<ion-button *ngIf="ipv6" slot="end" fill="clear" (click)="copy(ipv6)">
<ion-icon slot="icon-only" name="copy-outline"></ion-icon>
</ion-button>
</ion-item>
<ng-container *ngFor="let iface of server.networkInterfaces | keyvalue">
<ng-container *ngFor="let ipnet of iface.value.ipInfo">
<ion-item *tuiLet="ipnet.split('/')[0] as ipAddr">
<ion-label>
<h2>{{ iface.key }} ({{ ipAddr.includes("::") ? "IPv6" : "IPv4" }})</h2>
<p>{{ ipAddr }}</p>
</ion-label>
<ion-button slot="end" fill="clear" (click)="copy(ipAddr)">
<ion-icon slot="icon-only" name="copy-outline"></ion-icon>
</ion-button>
</ion-item>
</ng-container>
</ng-container>

<ion-item-divider>Device Credentials</ion-item-divider>
Expand Down
17 changes: 8 additions & 9 deletions web/projects/ui/src/app/services/api/mock-patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,17 @@ export const mockPatchData: DataModel = {
lastBackup: new Date(new Date().valueOf() - 604800001).toISOString(),
lanAddress: 'https://adjective-noun.local',
torAddress: 'https://myveryownspecialtoraddress.onion',
ipInfo: {
networkInterfaces: {
eth0: {
ipv4: '10.0.0.1',
ipv4Range: '10.0.0.1/24',
ipv6: null,
ipv6Range: null,
public: false,
ipInfo: ['10.0.0.1/24'],
},
wlan0: {
ipv4: '10.0.90.12',
ipv4Range: '10.0.90.12/24',
ipv6: 'FE80:CD00:0000:0CDE:1257:0000:211E:729CD',
ipv6Range: 'FE80:CD00:0000:0CDE:1257:0000:211E:729CD/64',
public: false,
ipInfo: [
'10.0.90.12/24',
'FE80:CD00:0000:0CDE:1257:0000:211E:729CD/64',
],
},
},
acme: null,
Expand Down

0 comments on commit 821460e

Please sign in to comment.