feat: group host-side /var/lib/hyperhive state into db/ forge/ matrix/ run/ subdirs with startup migration
This commit is contained in:
parent
cfafc9d93d
commit
14c7b0d406
15 changed files with 261 additions and 51 deletions
|
|
@ -20,20 +20,11 @@ const TOKEN_NAME_PREFIX: &str = "hyperhive";
|
|||
/// itself to push the meta repo + drive admin API calls (org
|
||||
/// creation, future webhook setup, etc.). Root-only.
|
||||
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. 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";
|
||||
/// Sibling marker for the `agent-configs` org avatar. Same one-shot
|
||||
/// semantics — delete to force the upload to re-run.
|
||||
const CONFIG_ORG_AVATAR_MARKER: &str = "/var/lib/hyperhive/forge-agent-configs-avatar-set";
|
||||
/// Per-agent marker written once the account email has been aligned to
|
||||
/// `{name}@hyperhive`. Skips the `PATCH /api/v1/admin/users/{name}`
|
||||
/// call on every subsequent `sync_agent` tick — that PATCH was resetting
|
||||
/// Forgejo's `use_custom_avatar` flag and clobbering the avatar uploaded
|
||||
/// by `forge-avatar-sync`. Delete to force re-alignment.
|
||||
const EMAIL_ALIGNED_MARKER_PREFIX: &str = "/var/lib/hyperhive/forge-email-aligned-";
|
||||
// Forge provisioning markers (`forge/core-avatar-set`,
|
||||
// `forge/agent-configs-avatar-set`, `forge/email-aligned-<name>`) live
|
||||
// in `crate::paths` — one-shot guards: the upload/align runs once, the
|
||||
// marker is written, subsequent startups skip. Delete one to force its
|
||||
// step to re-run.
|
||||
// Avatar PNGs are loaded at runtime from
|
||||
// `$HIVE_ASSETS_DIR/branding/{hyperhive,agent-configs}.png` via the
|
||||
// helpers in `hive_sh4re::assets`. The `agent-configs.png` is
|
||||
|
|
@ -221,8 +212,8 @@ async fn change_user_password(name: &str, password: &str) -> Result<()> {
|
|||
/// `login_name` (required by Forgejo's `EditUserOption` validator) and
|
||||
/// `source_id = 0` (local auth, the default for users hive-c0re creates).
|
||||
async fn ensure_user_email(name: &str) {
|
||||
let marker = format!("{EMAIL_ALIGNED_MARKER_PREFIX}{name}");
|
||||
if std::path::Path::new(&marker).exists() {
|
||||
let marker = crate::paths::forge_email_aligned_marker(name);
|
||||
if marker.exists() {
|
||||
return;
|
||||
}
|
||||
let Some(token) = core_token() else {
|
||||
|
|
@ -236,6 +227,9 @@ async fn ensure_user_email(name: &str) {
|
|||
let url = format!("{FORGE_HTTP}/api/v1/admin/users/{name}");
|
||||
match forge_http(reqwest::Method::PATCH, &url, &token, &body).await {
|
||||
Ok(status) if status.is_success() => {
|
||||
if let Some(parent) = marker.parent() {
|
||||
std::fs::create_dir_all(parent).ok();
|
||||
}
|
||||
std::fs::write(&marker, "").ok();
|
||||
tracing::info!(%name, %email, "forge: user email aligned");
|
||||
}
|
||||
|
|
@ -361,7 +355,7 @@ pub async fn provision_user_token(name: &str, password: Option<&str>) -> Result<
|
|||
/// — 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);
|
||||
let marker = crate::paths::forge_core_avatar_marker();
|
||||
if marker.exists() {
|
||||
return Ok(());
|
||||
}
|
||||
|
|
@ -392,7 +386,7 @@ async fn ensure_core_avatar(token: &str) -> Result<()> {
|
|||
/// endpoint is `POST /api/v1/orgs/{org}/avatar` with a base64-PNG
|
||||
/// JSON body — same shape as the admin user endpoint above.
|
||||
async fn ensure_config_org_avatar(token: &str) -> Result<()> {
|
||||
let marker = std::path::Path::new(CONFIG_ORG_AVATAR_MARKER);
|
||||
let marker = crate::paths::forge_config_org_avatar_marker();
|
||||
if marker.exists() {
|
||||
return Ok(());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue