Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ built = { version = "0.8", features = ["chrono"] }
insta = { version = "1", features = ["json"] }
tempfile = "3"
pretty_assertions = "1"
reqwest = { version = "0.12", default-features = false }
reqwest = { version = "0.12", default-features = false, features = ["stream"] }

[lints.rust]
unsafe_code = "warn"
Expand Down
6 changes: 5 additions & 1 deletion src/cli/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ pub struct ServeArgs {
/// Open the dashboard in your browser once the server is up.
#[arg(long)]
pub open: bool,
/// Acknowledge exposing all PM/cost/webhook data with no authentication.
/// Required whenever --host is not 127.0.0.1/localhost/::1.
#[arg(long)]
pub yes_expose: bool,
}

impl ServeArgs {
pub fn run(self) {
crate::dashboard::serve(&self.host, self.port, self.open);
crate::dashboard::serve(&self.host, self.port, self.open, self.yes_expose);
}
}
75 changes: 60 additions & 15 deletions src/dashboard/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ pub fn claims_json() -> String {
});
match result {
Ok(claims) => serde_json::to_string(&claims).unwrap_or_else(|_| "[]".into()),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] claims_json: {e}");
"[]".into()
}
}
}

Expand All @@ -35,14 +38,20 @@ pub fn claims_json() -> String {
pub fn workspaces_json() -> String {
match pm_db_readonly() {
Ok(conn) => workspaces_json_from(&conn),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] workspaces_json: {e}");
"[]".into()
}
}
}

fn workspaces_json_from(conn: &Connection) -> String {
match agentflare_backend::workspace::list(conn) {
Ok(rows) => serde_json::to_string(&rows).unwrap_or_else(|_| "[]".into()),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] workspaces_json_from: {e}");
"[]".into()
}
}
}

Expand All @@ -51,14 +60,20 @@ fn workspaces_json_from(conn: &Connection) -> String {
pub fn projects_json(workspace_id: &str) -> String {
match pm_db_readonly() {
Ok(conn) => projects_json_from(&conn, workspace_id),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] projects_json: {e}");
"[]".into()
}
}
}

fn projects_json_from(conn: &Connection, workspace_id: &str) -> String {
match agentflare_backend::project::list_by_workspace(conn, workspace_id) {
Ok(rows) => serde_json::to_string(&rows).unwrap_or_else(|_| "[]".into()),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] projects_json_from: {e}");
"[]".into()
}
}
}

Expand All @@ -67,14 +82,20 @@ fn projects_json_from(conn: &Connection, workspace_id: &str) -> String {
pub fn items_json(project_id: &str) -> String {
match pm_db_readonly() {
Ok(conn) => items_json_from(&conn, project_id),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] items_json: {e}");
"[]".into()
}
}
}

fn items_json_from(conn: &Connection, project_id: &str) -> String {
match agentflare_backend::item::list_by_project(conn, project_id) {
Ok(rows) => serde_json::to_string(&rows).unwrap_or_else(|_| "[]".into()),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] items_json_from: {e}");
"[]".into()
}
}
}

Expand All @@ -83,14 +104,20 @@ fn items_json_from(conn: &Connection, project_id: &str) -> String {
pub fn states_json(project_id: &str) -> String {
match pm_db_readonly() {
Ok(conn) => states_json_from(&conn, project_id),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] states_json: {e}");
"[]".into()
}
}
}

fn states_json_from(conn: &Connection, project_id: &str) -> String {
match agentflare_backend::state::list_by_project(conn, project_id) {
Ok(rows) => serde_json::to_string(&rows).unwrap_or_else(|_| "[]".into()),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] states_json_from: {e}");
"[]".into()
}
}
}

Expand All @@ -99,14 +126,20 @@ fn states_json_from(conn: &Connection, project_id: &str) -> String {
pub fn comments_json(item_id: &str) -> String {
match pm_db_readonly() {
Ok(conn) => comments_json_from(&conn, item_id),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] comments_json: {e}");
"[]".into()
}
}
}

fn comments_json_from(conn: &Connection, item_id: &str) -> String {
match agentflare_backend::comment::list_by_item(conn, item_id) {
Ok(rows) => serde_json::to_string(&rows).unwrap_or_else(|_| "[]".into()),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] comments_json_from: {e}");
"[]".into()
}
}
}

Expand All @@ -117,7 +150,10 @@ fn comments_json_from(conn: &Connection, item_id: &str) -> String {
pub fn labels_json(workspace_id: Option<&str>, project_id: Option<&str>) -> String {
match pm_db_readonly() {
Ok(conn) => labels_json_from(&conn, workspace_id, project_id),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] labels_json: {e}");
"[]".into()
}
}
}

Expand All @@ -133,7 +169,10 @@ fn labels_json_from(
};
match result {
Ok(rows) => serde_json::to_string(&rows).unwrap_or_else(|_| "[]".into()),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] labels_json_from: {e}");
"[]".into()
}
}
}

Expand All @@ -143,14 +182,20 @@ fn labels_json_from(
pub fn webhooks_json(workspace_id: &str) -> String {
match pm_db_readonly() {
Ok(conn) => webhooks_json_from(&conn, workspace_id),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] webhooks_json: {e}");
"[]".into()
}
}
}

fn webhooks_json_from(conn: &Connection, workspace_id: &str) -> String {
match agentflare_backend::webhook::list_logs_by_workspace(conn, workspace_id) {
Ok(rows) => serde_json::to_string(&rows).unwrap_or_else(|_| "[]".into()),
Err(_) => "[]".into(),
Err(e) => {
eprintln!("[dashboard/data] webhooks_json_from: {e}");
"[]".into()
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/dashboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ mod artifacts;
mod data;
mod server;

pub fn serve(host: &str, port: u16, open: bool) {
pub fn serve(host: &str, port: u16, open: bool, yes_expose: bool) {
let runtime = tokio::runtime::Runtime::new().expect("failed to build tokio runtime");
runtime.block_on(server::run(host, port, open));
runtime.block_on(server::run(host, port, open, yes_expose));
}

/// Best-effort: open a URL in the default browser. Never panics.
Expand Down
Loading
Loading