OXYGENHUB

Coverage / crates/hub/src/web/help.rs 96.2%

25 of 26 lines run, 8 of 16 functions · run #477 on main · run missed

1
//! `/help` (hub spec §6.3): getting started with this hub's own address,
2
//! remote name and certificate filled in, the keyboard, and a glossary
3
//! for people coming from GitHub.
4
5
use super::repo::Quickstart;
6
use super::{Page, Shell};
7
use crate::auth::Viewer;
8
use crate::Shared;
9
use askama::Template;
10
use axum::extract::State;
11
12
#[derive(Template)]
13
#[template(path = "help.html")]
14
pub struct HelpPage {
15
    shell: Shell,
16
    q: Quickstart,
17
    base: String,
18
    /// The signed-in user, or a placeholder, for example URLs.
19
    who: String,
20
}
21
221×
pub async fn help(State(app): State<Shared>, viewer: Viewer) -> Page<HelpPage> {
231×
    let shell = Shell::new(&app, "/help", &viewer);
241×
    let who = shell.user.clone().unwrap_or_else(|| "OWNER".into());
251×
    let base = app.config.base_url().trim_end_matches('/').to_string();
261×
    Page(HelpPage { shell, q: Quickstart::new(&app, true), base, who })
271×
}
28
29
impl HelpPage {
30
    /// An example repository address on this hub.
312×
    pub fn repo_url(&self) -> String {
322×
        format!("{}/{}/REPOSITORY", self.base, self.who)
332×
    }
34
35
    /// An agent's own home, keyless, with its grant kept (#287).
361×
    pub fn agent_home_cmd(&self) -> String {
371×
        format!(
38
            "export OXY_HOME=~/.oxy-agents/claude\noxy config --user author.signer keyless\noxy config --user keyless.hub {base}\noxy config --user core.sign seal\noxy auth grant {base}   # paste the token, then Ctrl-D",
39
            base = self.base
40
        )
411×
    }
42
43
    /// A repository's trust policy admitting an agent's certified keys (#287).
441×
    pub fn subject_grant_cmd(&self) -> String {
451×
        format!(
46
            "curl -fsSL {}/.well-known/oxyhub-key -o hub.identity\noxy policy grant-subject agent:claude@{} --issuer hub.identity --scope changes,refs",
47
            self.base, self.who
48
        )
491×
    }
50
511×
    pub fn delegate_cmd(&self) -> String {
521×
        format!(
53
            "curl -fsSL {}/.well-known/oxyhub-key -o hub.identity\noxy identity delegate add hub.identity --scope changes,refs",
54
            self.base
55
        )
561×
    }
57
581×
    pub fn clone_cmd(&self) -> String {
591×
        let url = self.repo_url();
601×
        match &self.q.ca_url {
610×
            Some(_) => format!("OXY_CA={} oxy clone {url}", self.q.ca_file),
621×
            None => format!("oxy clone {url}"),
63
        }
641×
    }
65
}