Compare commits
No commits in common. "ce539559d55350cb36cea464141ef5510c806476" and "832c2f86c5be617b236d721cc6c290f9f045f292" have entirely different histories.
ce539559d5
...
832c2f86c5
4 changed files with 0 additions and 43 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -585,7 +585,6 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"axum",
|
"axum",
|
||||||
"base64",
|
|
||||||
"clap",
|
"clap",
|
||||||
"hive-fr0nt",
|
"hive-fr0nt",
|
||||||
"hive-sh4re",
|
"hive-sh4re",
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ must_use_candidate = "allow"
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
axum = { version = "0.8", features = ["ws"] }
|
axum = { version = "0.8", features = ["ws"] }
|
||||||
base64 = "0.22"
|
|
||||||
clap = { version = "4", features = ["derive"] }
|
clap = { version = "4", features = ["derive"] }
|
||||||
hive-fr0nt = { path = "hive-fr0nt" }
|
hive-fr0nt = { path = "hive-fr0nt" }
|
||||||
hive-sh4re = { path = "hive-sh4re" }
|
hive-sh4re = { path = "hive-sh4re" }
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ workspace = true
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
axum.workspace = true
|
axum.workspace = true
|
||||||
base64.workspace = true
|
|
||||||
reqwest.workspace = true
|
reqwest.workspace = true
|
||||||
clap.workspace = true
|
clap.workspace = true
|
||||||
hive-fr0nt.workspace = true
|
hive-fr0nt.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use base64::Engine;
|
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
|
|
||||||
|
|
@ -33,16 +32,6 @@ const TOKEN_NAME_PREFIX: &str = "hyperhive";
|
||||||
/// itself to push the meta repo + drive admin API calls (org
|
/// itself to push the meta repo + drive admin API calls (org
|
||||||
/// creation, future webhook setup, etc.). Root-only.
|
/// creation, future webhook setup, etc.). Root-only.
|
||||||
const CORE_TOKEN_PATH: &str = "/var/lib/hyperhive/forge-core-token";
|
const CORE_TOKEN_PATH: &str = "/var/lib/hyperhive/forge-core-token";
|
||||||
/// Marker that records whether `ensure_core_avatar` has successfully
|
|
||||||
/// uploaded the hyperhive logo as `core`'s avatar (issue #320). One-shot:
|
|
||||||
/// the upload runs once, the marker is written, subsequent startups skip
|
|
||||||
/// the call. Delete to force re-upload.
|
|
||||||
const CORE_AVATAR_MARKER: &str = "/var/lib/hyperhive/forge-core-avatar-set";
|
|
||||||
/// Hyperhive logo bytes, baked into the daemon. Uploaded once via the
|
|
||||||
/// admin avatar API so the `core` Forgejo user shows the project mark
|
|
||||||
/// next to commits in `agent-configs/*`, `core/meta`, etc. instead of
|
|
||||||
/// the default hash identicon.
|
|
||||||
const CORE_AVATAR_PNG: &[u8] = include_bytes!("../../branding/hyperhive.png");
|
|
||||||
/// Forgejo org grouping every agent's applied config repo. Core is a
|
/// Forgejo org grouping every agent's applied config repo. Core is a
|
||||||
/// site admin and reads + writes every repo here; agents are NOT
|
/// site admin and reads + writes every repo here; agents are NOT
|
||||||
/// members and the repos are private, so no agent — not even the one
|
/// members and the repos are private, so no agent — not even the one
|
||||||
|
|
@ -277,32 +266,6 @@ pub async fn ensure_user_for(name: &str) -> Result<()> {
|
||||||
mint_and_persist_token(name, &token_path(name)).await
|
mint_and_persist_token(name, &token_path(name)).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set `core`'s Forgejo avatar to the hyperhive logo once, then
|
|
||||||
/// remember it so subsequent startups don't re-upload (issue #320).
|
|
||||||
/// Best-effort — any non-2xx is logged at the caller; the project
|
|
||||||
/// runs fine with the default hash identicon.
|
|
||||||
async fn ensure_core_avatar(token: &str) -> Result<()> {
|
|
||||||
let marker = std::path::Path::new(CORE_AVATAR_MARKER);
|
|
||||||
if marker.exists() {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
let body = format!(
|
|
||||||
r#"{{"image":"{}"}}"#,
|
|
||||||
base64::engine::general_purpose::STANDARD.encode(CORE_AVATAR_PNG),
|
|
||||||
);
|
|
||||||
let url = format!("{FORGE_HTTP}/api/v1/admin/users/core/avatar");
|
|
||||||
let status = forge_http(reqwest::Method::POST, &url, token, &body).await?;
|
|
||||||
if !status.is_success() {
|
|
||||||
anyhow::bail!("set core avatar: HTTP {status}");
|
|
||||||
}
|
|
||||||
if let Some(parent) = marker.parent() {
|
|
||||||
std::fs::create_dir_all(parent).ok();
|
|
||||||
}
|
|
||||||
std::fs::write(marker, "").ok();
|
|
||||||
tracing::info!("forge: set core user avatar to hyperhive logo");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ensure the bootstrap `core` admin user + a token at
|
/// Ensure the bootstrap `core` admin user + a token at
|
||||||
/// `CORE_TOKEN_PATH`. The token is what hive-c0re uses for forgejo
|
/// `CORE_TOKEN_PATH`. The token is what hive-c0re uses for forgejo
|
||||||
/// API calls (org creation now, meta-repo push later). Returns the
|
/// API calls (org creation now, meta-repo push later). Returns the
|
||||||
|
|
@ -628,9 +591,6 @@ pub async fn ensure_all() {
|
||||||
if let Err(e) = ensure_repo("meta", token).await {
|
if let Err(e) = ensure_repo("meta", token).await {
|
||||||
tracing::warn!(error = ?e, "forge: ensure_repo core/meta failed");
|
tracing::warn!(error = ?e, "forge: ensure_repo core/meta failed");
|
||||||
}
|
}
|
||||||
if let Err(e) = ensure_core_avatar(token).await {
|
|
||||||
tracing::warn!(error = ?e, "forge: ensure_core_avatar failed");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let Ok(containers) = crate::lifecycle::list().await else {
|
let Ok(containers) = crate::lifecycle::list().await else {
|
||||||
tracing::warn!("forge: nixos-container list failed; skipping user sweep");
|
tracing::warn!("forge: nixos-container list failed; skipping user sweep");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue