refactor(#2285): repoint all hive-c0re host-path consumers to paths.rs
This commit is contained in:
parent
4162f557c9
commit
187c364feb
16 changed files with 95 additions and 125 deletions
|
|
@ -7,7 +7,7 @@
|
|||
//! the full UIAA round-trip, token-file shape, and host/container
|
||||
//! bind-mount layout.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use reqwest::StatusCode;
|
||||
|
|
@ -22,11 +22,6 @@ const MATRIX_CONTAINER: &str = "hive-matrix";
|
|||
/// netns so `localhost:<port>` resolves both from the daemon and from
|
||||
/// inside any sub-agent container.
|
||||
const MATRIX_HTTP: &str = "http://localhost:8008";
|
||||
/// Host path of the matrix registration token. Must match
|
||||
/// `hyperhive.matrix.registrationTokenFile` in `nix/modules/hive-matrix.nix`
|
||||
/// (same path is bind-mounted read-only into the tuwunel container so
|
||||
/// the homeserver can read it via `registration_token_file`).
|
||||
const REGISTER_TOKEN_PATH: &str = "/var/lib/hyperhive/matrix-register-token";
|
||||
/// Length (bytes) of the random registration token. 32 raw bytes ⇒
|
||||
/// 64-char hex string; comfortable for a long-lived shared secret.
|
||||
const REGISTER_TOKEN_BYTES: usize = 32;
|
||||
|
|
@ -148,8 +143,8 @@ fn random_hex(n: usize) -> Result<String> {
|
|||
/// against the same secret hive-c0re holds.
|
||||
pub fn ensure_register_token() -> Result<String> {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let path = Path::new(REGISTER_TOKEN_PATH);
|
||||
if let Ok(existing) = std::fs::read_to_string(path) {
|
||||
let path = crate::paths::matrix_register_token();
|
||||
if let Ok(existing) = std::fs::read_to_string(&path) {
|
||||
let trimmed = existing.trim().to_owned();
|
||||
if !trimmed.is_empty() {
|
||||
return Ok(trimmed);
|
||||
|
|
@ -159,9 +154,9 @@ pub fn ensure_register_token() -> Result<String> {
|
|||
if let Some(parent) = path.parent() {
|
||||
std::fs::create_dir_all(parent).ok();
|
||||
}
|
||||
std::fs::write(path, format!("{token}\n"))
|
||||
std::fs::write(&path, format!("{token}\n"))
|
||||
.with_context(|| format!("write registration token to {}", path.display()))?;
|
||||
let _ = std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600));
|
||||
let _ = std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o600));
|
||||
tracing::info!(path = %path.display(), "matrix: generated registration token");
|
||||
Ok(token)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue