From 5d8e3f80254f20eb6672701fad5f116a3b05dbc3 Mon Sep 17 00:00:00 2001 From: soryu Date: Tue, 20 Jan 2026 00:23:49 +0000 Subject: Fix: auth for CLI and CLI SIGTERM --- makima/src/daemon/api/client.rs | 22 ++++++++++++++++++++++ makima/src/daemon/api/contract.rs | 33 +++++++++++++++++++++++++++++++++ makima/src/daemon/api/supervisor.rs | 25 +++++++++++++++++++++++++ 3 files changed, 80 insertions(+) (limited to 'makima/src/daemon/api') diff --git a/makima/src/daemon/api/client.rs b/makima/src/daemon/api/client.rs index 2318d5a..ca1b2a8 100644 --- a/makima/src/daemon/api/client.rs +++ b/makima/src/daemon/api/client.rs @@ -105,6 +105,28 @@ impl ApiClient { self.handle_response(response).await } + /// Make a DELETE request. + pub async fn delete(&self, path: &str) -> Result<(), ApiError> { + let url = format!("{}{}", self.base_url, path); + let response = self.client + .delete(&url) + .header("X-Makima-Tool-Key", &self.api_key) + .header("X-Makima-API-Key", &self.api_key) + .send() + .await?; + + let status = response.status(); + if !status.is_success() { + let body = response.text().await.unwrap_or_default(); + return Err(ApiError::Api { + status: status.as_u16(), + message: body, + }); + } + + Ok(()) + } + /// Handle API response. async fn handle_response( &self, diff --git a/makima/src/daemon/api/contract.rs b/makima/src/daemon/api/contract.rs index aac6b94..f7fa696 100644 --- a/makima/src/daemon/api/contract.rs +++ b/makima/src/daemon/api/contract.rs @@ -41,7 +41,40 @@ pub struct CreateFileRequest { pub content: String, } +/// Request to update a contract. +#[derive(Serialize, Default)] +#[serde(rename_all = "camelCase")] +pub struct UpdateContractRequest { + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub description: Option, +} + impl ApiClient { + /// List all contracts for the authenticated user. + pub async fn list_contracts(&self) -> Result { + self.get("/api/v1/contracts").await + } + + /// Delete a contract. + pub async fn delete_contract(&self, contract_id: Uuid) -> Result<(), ApiError> { + self.delete(&format!("/api/v1/contracts/{}", contract_id)) + .await + } + + /// Update a contract. + pub async fn update_contract( + &self, + contract_id: Uuid, + name: Option, + description: Option, + ) -> Result { + let req = UpdateContractRequest { name, description }; + self.put(&format!("/api/v1/contracts/{}", contract_id), &req) + .await + } + /// Get contract status. pub async fn contract_status(&self, contract_id: Uuid) -> Result { self.get(&format!("/api/v1/contracts/{}/daemon/status", contract_id)) diff --git a/makima/src/daemon/api/supervisor.rs b/makima/src/daemon/api/supervisor.rs index 1dc699e..9614cfc 100644 --- a/makima/src/daemon/api/supervisor.rs +++ b/makima/src/daemon/api/supervisor.rs @@ -248,4 +248,29 @@ impl ApiClient { self.get(&format!("/api/v1/mesh/tasks/{}/output", task_id)) .await } + + /// Delete a task. + pub async fn delete_task(&self, task_id: Uuid) -> Result<(), ApiError> { + self.delete(&format!("/api/v1/mesh/tasks/{}", task_id)).await + } + + /// Update a task. + pub async fn update_task( + &self, + task_id: Uuid, + name: Option, + plan: Option, + ) -> Result { + #[derive(Serialize)] + #[serde(rename_all = "camelCase")] + struct UpdateTaskRequest { + #[serde(skip_serializing_if = "Option::is_none")] + name: Option, + #[serde(skip_serializing_if = "Option::is_none")] + plan: Option, + } + let req = UpdateTaskRequest { name, plan }; + self.put(&format!("/api/v1/mesh/tasks/{}", task_id), &req) + .await + } } -- cgit v1.2.3