Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7cda3064e | ||
|
|
484f479b90 | ||
|
|
2d3417b7d3 | ||
|
|
cc14543ced |
@@ -12,7 +12,7 @@ concurrency:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish:
|
publish:
|
||||||
runs-on: alkane-verify
|
runs-on: alkane-ci
|
||||||
container:
|
container:
|
||||||
image: gitea.bluefla.re/blueflare/alkane-ci@sha256:ad56db2fc456a3f1c68c715ba44309751cb5c455376d9f797ac346833c011e15
|
image: gitea.bluefla.re/blueflare/alkane-ci@sha256:ad56db2fc456a3f1c68c715ba44309751cb5c455376d9f797ac346833c011e15
|
||||||
permissions:
|
permissions:
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ concurrency:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish:
|
publish:
|
||||||
runs-on: alkane-verify
|
runs-on: alkane-ci
|
||||||
container:
|
container:
|
||||||
image: gitea.bluefla.re/blueflare/alkane-ci@sha256:ad56db2fc456a3f1c68c715ba44309751cb5c455376d9f797ac346833c011e15
|
image: gitea.bluefla.re/blueflare/alkane-ci@sha256:ad56db2fc456a3f1c68c715ba44309751cb5c455376d9f797ac346833c011e15
|
||||||
permissions:
|
permissions:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ concurrency:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
source:
|
source:
|
||||||
runs-on: alkane-fast
|
runs-on: alkane-ci
|
||||||
container:
|
container:
|
||||||
image: gitea.bluefla.re/blueflare/alkane-ci@sha256:ad56db2fc456a3f1c68c715ba44309751cb5c455376d9f797ac346833c011e15
|
image: gitea.bluefla.re/blueflare/alkane-ci@sha256:ad56db2fc456a3f1c68c715ba44309751cb5c455376d9f797ac346833c011e15
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ concurrency:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: alkane-verify
|
runs-on: alkane-ci
|
||||||
container:
|
container:
|
||||||
image: gitea.bluefla.re/blueflare/alkane-ci@sha256:ad56db2fc456a3f1c68c715ba44309751cb5c455376d9f797ac346833c011e15
|
image: gitea.bluefla.re/blueflare/alkane-ci@sha256:ad56db2fc456a3f1c68c715ba44309751cb5c455376d9f797ac346833c011e15
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -58,10 +58,12 @@ command -v arm-linux-gnueabihf-strip >/dev/null 2>&1 && arm-linux-gnueabihf-stri
|
|||||||
echo "repacking the SDK rootfs with the console + overlay (under fakeroot)"
|
echo "repacking the SDK rootfs with the console + overlay (under fakeroot)"
|
||||||
cat > "$WORK/pack.sh" <<'PACK'
|
cat > "$WORK/pack.sh" <<'PACK'
|
||||||
set -e
|
set -e
|
||||||
RFS=$1; SDK_OUT=$2; WORK=$3; OVERLAY=$4
|
RFS=$1; SDK_OUT=$2; WORK=$3; OVERLAY=$4; VERSION=$5
|
||||||
mkdir -p "$RFS"
|
mkdir -p "$RFS"
|
||||||
( cd "$RFS" && zcat "$SDK_OUT/rootfs.cpio.gz" | cpio -idm --quiet )
|
( cd "$RFS" && zcat "$SDK_OUT/rootfs.cpio.gz" | cpio -idm --quiet )
|
||||||
install -D -m 0755 "$WORK/alkane-os" "$RFS/usr/bin/alkane-os"
|
install -D -m 0755 "$WORK/alkane-os" "$RFS/usr/bin/alkane-os"
|
||||||
|
# The .afw version, reported by GET /api/identity (fleet discovery).
|
||||||
|
printf '%s\n' "$VERSION" > "$RFS/etc/alkane-os-version"
|
||||||
if [ -d "$OVERLAY" ]; then
|
if [ -d "$OVERLAY" ]; then
|
||||||
( cd "$OVERLAY" && find . -type f ) | while IFS= read -r f; do
|
( cd "$OVERLAY" && find . -type f ) | while IFS= read -r f; do
|
||||||
install -D -m 0755 "$OVERLAY/${f#./}" "$RFS/${f#./}"
|
install -D -m 0755 "$OVERLAY/${f#./}" "$RFS/${f#./}"
|
||||||
@@ -69,7 +71,7 @@ if [ -d "$OVERLAY" ]; then
|
|||||||
fi
|
fi
|
||||||
( cd "$RFS" && find . | cpio -o -H newc --owner=0:0 --quiet | gzip -9 > "$WORK/in/rootfs.cpio.gz" )
|
( cd "$RFS" && find . | cpio -o -H newc --owner=0:0 --quiet | gzip -9 > "$WORK/in/rootfs.cpio.gz" )
|
||||||
PACK
|
PACK
|
||||||
fakeroot -- bash "$WORK/pack.sh" "$WORK/rootfs" "$SDK_OUT" "$WORK" "$ROOT/image/overlay"
|
fakeroot -- bash "$WORK/pack.sh" "$WORK/rootfs" "$SDK_OUT" "$WORK" "$ROOT/image/overlay" "$VERSION"
|
||||||
|
|
||||||
cp "$SDK_OUT/zImage" "$WORK/in/zImage"
|
cp "$SDK_OUT/zImage" "$WORK/in/zImage"
|
||||||
cp "$SDK_OUT/zynq-alkane.dtb" "$WORK/in/zynq-alkane.dtb"
|
cp "$SDK_OUT/zynq-alkane.dtb" "$WORK/in/zynq-alkane.dtb"
|
||||||
|
|||||||
+90
-3
@@ -221,8 +221,11 @@ fn route(stream: &mut TcpStream, ctx: &WebContext, request: &Request) -> io::Res
|
|||||||
// The read-only miner-state JSON stays open (it is the interface of record
|
// The read-only miner-state JSON stays open (it is the interface of record
|
||||||
// and is already exposed on the cgminer socket). Everything else - the HTML
|
// and is already exposed on the cgminer socket). Everything else - the HTML
|
||||||
// console, host reads, and every mutation - needs a live session.
|
// console, host reads, and every mutation - needs a live session.
|
||||||
let open_api =
|
let open_api = method == "GET"
|
||||||
method == "GET" && matches!(path, "/api/hardware" | "/api/summary" | "/api/control");
|
&& matches!(
|
||||||
|
path,
|
||||||
|
"/api/hardware" | "/api/summary" | "/api/control" | "/api/identity"
|
||||||
|
);
|
||||||
let authed = request.wsid.as_deref().is_some_and(|w| ctx.auth.valid(w));
|
let authed = request.wsid.as_deref().is_some_and(|w| ctx.auth.valid(w));
|
||||||
if !authed && !open_api {
|
if !authed && !open_api {
|
||||||
if method == "GET" && !path.starts_with("/api/") {
|
if method == "GET" && !path.starts_with("/api/") {
|
||||||
@@ -252,6 +255,7 @@ fn route(stream: &mut TcpStream, ctx: &WebContext, request: &Request) -> io::Res
|
|||||||
("GET", "/api/summary") => {
|
("GET", "/api/summary") => {
|
||||||
json_response(stream, &bus.read_state_or(topics::SUMMARY, json!({})))
|
json_response(stream, &bus.read_state_or(topics::SUMMARY, json!({})))
|
||||||
}
|
}
|
||||||
|
("GET", "/api/identity") => json_response(stream, &identity(Path::new("/"))),
|
||||||
("GET", "/api/control") => json_response(
|
("GET", "/api/control") => json_response(
|
||||||
stream,
|
stream,
|
||||||
&bus.read_state_or(
|
&bus.read_state_or(
|
||||||
@@ -519,6 +523,39 @@ fn auth_local(stream: &mut TcpStream, ctx: &WebContext, request: &Request) -> io
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Read-only identity for network discovery (alkane-toolkit's fleet scan finds
|
||||||
|
/// Alkane boards by it: they have no cgminer socket or vendor web UI for a
|
||||||
|
/// generic scanner to recognise). Public like the other read-only state. It
|
||||||
|
/// carries no secret, only what a stock miner also exposes: OS and version, the
|
||||||
|
/// board family, SDK revision, hostname, MAC and kernel. `root` is the
|
||||||
|
/// filesystem root (the real one on a board; a temp dir in tests).
|
||||||
|
fn identity(root: &Path) -> Value {
|
||||||
|
let read = |rel: &str| {
|
||||||
|
fs::read_to_string(root.join(rel))
|
||||||
|
.ok()
|
||||||
|
.map(|text| text.trim().to_string())
|
||||||
|
.filter(|text| !text.is_empty())
|
||||||
|
};
|
||||||
|
let os_release = read("etc/os-release").unwrap_or_default();
|
||||||
|
let release_field = |key: &str| {
|
||||||
|
os_release.lines().find_map(|line| {
|
||||||
|
line.strip_prefix(key)
|
||||||
|
.and_then(|rest| rest.strip_prefix('='))
|
||||||
|
.map(|value| value.trim_matches('"').to_string())
|
||||||
|
})
|
||||||
|
};
|
||||||
|
json!({
|
||||||
|
"os": "alkane-os",
|
||||||
|
"os_version": read("etc/alkane-os-version")
|
||||||
|
.unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string()),
|
||||||
|
"board": release_field("VARIANT_ID"),
|
||||||
|
"sdk_revision": release_field("VERSION_ID"),
|
||||||
|
"hostname": read("proc/sys/kernel/hostname"),
|
||||||
|
"mac": read("sys/class/net/eth0/address"),
|
||||||
|
"kernel": read("proc/sys/kernel/osrelease"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn json_response(stream: &mut TcpStream, value: &Value) -> io::Result<()> {
|
fn json_response(stream: &mut TcpStream, value: &Value) -> io::Result<()> {
|
||||||
respond(
|
respond(
|
||||||
stream,
|
stream,
|
||||||
@@ -1019,13 +1056,63 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn the_api_serves_state_from_the_bus() {
|
fn the_api_serves_state_from_the_bus() {
|
||||||
for path in ["/api/hardware", "/api/summary", "/api/control"] {
|
for path in [
|
||||||
|
"/api/hardware",
|
||||||
|
"/api/summary",
|
||||||
|
"/api/control",
|
||||||
|
"/api/identity",
|
||||||
|
] {
|
||||||
let reply = client(&format!("GET {path} HTTP/1.1\r\nHost: x\r\n\r\n"));
|
let reply = client(&format!("GET {path} HTTP/1.1\r\nHost: x\r\n\r\n"));
|
||||||
assert!(reply.starts_with("HTTP/1.1 200 OK"), "{path}");
|
assert!(reply.starts_with("HTTP/1.1 200 OK"), "{path}");
|
||||||
assert!(reply.contains("application/json"));
|
assert!(reply.contains("application/json"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_identity_api_is_public_and_names_alkane() {
|
||||||
|
// No session cookie: discovery must work before anyone signs in.
|
||||||
|
let reply = client("GET /api/identity HTTP/1.1\r\nHost: x\r\n\r\n");
|
||||||
|
assert!(reply.starts_with("HTTP/1.1 200 OK"), "{reply}");
|
||||||
|
let body = reply.split("\r\n\r\n").nth(1).unwrap_or("");
|
||||||
|
let doc: Value = serde_json::from_str(body).unwrap_or_else(|_| json!({}));
|
||||||
|
assert_eq!(doc["os"], "alkane-os");
|
||||||
|
assert!(doc["os_version"].as_str().is_some_and(|v| !v.is_empty()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn identity_reads_the_board_files() {
|
||||||
|
let root = std::env::temp_dir().join(format!("alkane-identity-{}", std::process::id()));
|
||||||
|
for dir in ["etc", "proc/sys/kernel", "sys/class/net/eth0"] {
|
||||||
|
fs::create_dir_all(root.join(dir)).unwrap();
|
||||||
|
}
|
||||||
|
fs::write(
|
||||||
|
root.join("etc/os-release"),
|
||||||
|
"NAME=\"Alkane OS\"\nID=alkane\nVERSION_ID=6a9080ac82c1\nVARIANT_ID=zynq-7010\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
fs::write(root.join("etc/alkane-os-version"), "0.1.2\n").unwrap();
|
||||||
|
fs::write(root.join("proc/sys/kernel/hostname"), "alkane-zynq\n").unwrap();
|
||||||
|
fs::write(root.join("proc/sys/kernel/osrelease"), "6.18.48\n").unwrap();
|
||||||
|
fs::write(
|
||||||
|
root.join("sys/class/net/eth0/address"),
|
||||||
|
"26:4e:52:8b:e2:48\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let doc = identity(&root);
|
||||||
|
let _ = fs::remove_dir_all(&root);
|
||||||
|
assert_eq!(doc["os"], "alkane-os");
|
||||||
|
assert_eq!(doc["os_version"], "0.1.2");
|
||||||
|
assert_eq!(doc["board"], "zynq-7010");
|
||||||
|
assert_eq!(doc["sdk_revision"], "6a9080ac82c1");
|
||||||
|
assert_eq!(doc["hostname"], "alkane-zynq");
|
||||||
|
assert_eq!(doc["mac"], "26:4e:52:8b:e2:48");
|
||||||
|
assert_eq!(doc["kernel"], "6.18.48");
|
||||||
|
// Absent files read as null, never a panic.
|
||||||
|
let bare = identity(Path::new("/nonexistent-alkane-root"));
|
||||||
|
assert_eq!(bare["os"], "alkane-os");
|
||||||
|
assert!(bare["board"].is_null() && bare["mac"].is_null());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn the_control_api_reports_operator_state() {
|
fn the_control_api_reports_operator_state() {
|
||||||
let reply = client("GET /api/control HTTP/1.1\r\nHost: x\r\n\r\n");
|
let reply = client("GET /api/control HTTP/1.1\r\nHost: x\r\n\r\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user