feat(etcd): add cluster operations and access control
This commit is contained in:
55 files changed
+7502
-750
No files matched your search
@@ -3,10 +3,12 @@ use tauri::State;
|
||||
|
||||
use crate::commands::connection::{ensure_connection_writable, AppState};
|
||||
use dbx_core::agent_kv::{
|
||||
KvDeleteOptions, KvDeleteResponse, KvGetOptions, KvGetResponse, KvHistoryRequest, KvHistoryResponse, KvInt64,
|
||||
KvListPrefixResponse, KvPutOptions, KvPutResponse, KvRangeOptions, KvRenameRequest, KvRenameResponse,
|
||||
KvStatusResponse, KvValue,
|
||||
EtcdDefragResponse, EtcdLeaseListResponse, EtcdPreflightRequest, EtcdPreflightResponse, EtcdWatchPollResponse,
|
||||
EtcdWatchStartRequest, EtcdWatchStartResponse, KvDeleteOptions, KvDeleteResponse, KvGetOptions, KvGetResponse,
|
||||
KvHistoryRequest, KvHistoryResponse, KvInt64, KvListPrefixResponse, KvPutOptions, KvPutResponse, KvRangeOptions,
|
||||
KvRenameRequest, KvRenameResponse, KvStatusResponse, KvValue,
|
||||
};
|
||||
use dbx_core::db::agent_driver::AgentKvMethod;
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn etcd_list_prefix(
|
||||
@@ -125,3 +127,185 @@ pub async fn etcd_history(
|
||||
pub async fn etcd_status(state: State<'_, Arc<AppState>>, connection_id: String) -> Result<KvStatusResponse, String> {
|
||||
dbx_core::agent_kv::kv_status_core(&state, &connection_id).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn etcd_preflight(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
connection_id: String,
|
||||
request: EtcdPreflightRequest,
|
||||
) -> Result<EtcdPreflightResponse, String> {
|
||||
ensure_connection_writable(&state, &connection_id, "Dangerous etcd operation").await?;
|
||||
dbx_core::agent_kv::etcd_preflight_core(&state, &connection_id, request).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn etcd_compact(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
connection_id: String,
|
||||
revision: KvInt64,
|
||||
preflight_token: String,
|
||||
confirmation_text: String,
|
||||
) -> Result<serde_json::Value, String> {
|
||||
ensure_connection_writable(&state, &connection_id, "Compact").await?;
|
||||
let params = serde_json::json!({ "revision": revision.clone() });
|
||||
dbx_core::agent_kv::etcd_consume_preflight_core(
|
||||
&state,
|
||||
&connection_id,
|
||||
"compact",
|
||||
¶ms,
|
||||
&preflight_token,
|
||||
&confirmation_text,
|
||||
)
|
||||
.await?;
|
||||
dbx_core::agent_kv::etcd_compact_core(&state, &connection_id, revision).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn etcd_defrag(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
connection_id: String,
|
||||
endpoints: Vec<String>,
|
||||
preflight_token: String,
|
||||
confirmation_text: String,
|
||||
) -> Result<EtcdDefragResponse, String> {
|
||||
ensure_connection_writable(&state, &connection_id, "Defrag").await?;
|
||||
let params = serde_json::json!({ "endpoints": endpoints.clone() });
|
||||
dbx_core::agent_kv::etcd_consume_preflight_core(
|
||||
&state,
|
||||
&connection_id,
|
||||
"defrag",
|
||||
¶ms,
|
||||
&preflight_token,
|
||||
&confirmation_text,
|
||||
)
|
||||
.await?;
|
||||
dbx_core::agent_kv::etcd_defrag_core(&state, &connection_id, endpoints).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn etcd_watch_start(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
connection_id: String,
|
||||
request: EtcdWatchStartRequest,
|
||||
) -> Result<EtcdWatchStartResponse, String> {
|
||||
dbx_core::agent_kv::etcd_watch_start_core(&state, &connection_id, request).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn etcd_watch_poll(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
connection_id: String,
|
||||
watch_id: String,
|
||||
) -> Result<EtcdWatchPollResponse, String> {
|
||||
dbx_core::agent_kv::etcd_watch_poll_core(&state, &connection_id, &watch_id).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn etcd_watch_stop(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
connection_id: String,
|
||||
watch_id: String,
|
||||
) -> Result<serde_json::Value, String> {
|
||||
dbx_core::agent_kv::etcd_watch_stop_core(&state, &connection_id, &watch_id).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn etcd_lease_list(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
connection_id: String,
|
||||
limit: Option<usize>,
|
||||
continuation: Option<String>,
|
||||
) -> Result<EtcdLeaseListResponse, String> {
|
||||
dbx_core::agent_kv::etcd_lease_list_core(&state, &connection_id, limit.unwrap_or(100), continuation.as_deref())
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn etcd_lease_call(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
connection_id: String,
|
||||
operation: String,
|
||||
params: serde_json::Value,
|
||||
preflight_token: Option<String>,
|
||||
confirmation_text: Option<String>,
|
||||
) -> Result<serde_json::Value, String> {
|
||||
let (method, write) = match operation.as_str() {
|
||||
"get" => (AgentKvMethod::LeaseGet, false),
|
||||
"grant" => (AgentKvMethod::LeaseGrant, true),
|
||||
"keepalive" => (AgentKvMethod::LeaseKeepalive, true),
|
||||
"revoke" => (AgentKvMethod::LeaseRevoke, true),
|
||||
_ => return Err("Unsupported etcd lease operation".to_string()),
|
||||
};
|
||||
if write {
|
||||
ensure_connection_writable(&state, &connection_id, "Lease operation").await?;
|
||||
}
|
||||
if operation == "revoke" {
|
||||
dbx_core::agent_kv::etcd_consume_preflight_core(
|
||||
&state,
|
||||
&connection_id,
|
||||
"lease_revoke",
|
||||
¶ms,
|
||||
preflight_token.as_deref().ok_or("ETCD_PREFLIGHT_REQUIRED: Request a preflight confirmation")?,
|
||||
confirmation_text.as_deref().ok_or("ETCD_PREFLIGHT_REQUIRED: Request a preflight confirmation")?,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
dbx_core::agent_kv::etcd_lease_call_core(&state, &connection_id, method, params).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn etcd_auth_call(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
connection_id: String,
|
||||
operation: String,
|
||||
params: serde_json::Value,
|
||||
preflight_token: Option<String>,
|
||||
confirmation_text: Option<String>,
|
||||
) -> Result<serde_json::Value, String> {
|
||||
let (method, write) = match operation.as_str() {
|
||||
"user_list" => (AgentKvMethod::AuthUserList, false),
|
||||
"user_get" => (AgentKvMethod::AuthUserGet, false),
|
||||
"user_add" => (AgentKvMethod::AuthUserAdd, true),
|
||||
"user_delete" => (AgentKvMethod::AuthUserDelete, true),
|
||||
"user_change_password" => (AgentKvMethod::AuthUserChangePassword, true),
|
||||
"user_grant_role" => (AgentKvMethod::AuthUserGrantRole, true),
|
||||
"user_revoke_role" => (AgentKvMethod::AuthUserRevokeRole, true),
|
||||
"role_list" => (AgentKvMethod::AuthRoleList, false),
|
||||
"role_get" => (AgentKvMethod::AuthRoleGet, false),
|
||||
"role_add" => (AgentKvMethod::AuthRoleAdd, true),
|
||||
"role_delete" => (AgentKvMethod::AuthRoleDelete, true),
|
||||
"role_grant_permission" => (AgentKvMethod::AuthRoleGrantPermission, true),
|
||||
"role_revoke_permission" => (AgentKvMethod::AuthRoleRevokePermission, true),
|
||||
_ => return Err("Unsupported etcd Auth operation".to_string()),
|
||||
};
|
||||
if write {
|
||||
ensure_connection_writable(&state, &connection_id, "Auth operation").await?;
|
||||
}
|
||||
if let Some(action) = auth_preflight_action(&operation) {
|
||||
dbx_core::agent_kv::etcd_consume_preflight_core(
|
||||
&state,
|
||||
&connection_id,
|
||||
action,
|
||||
¶ms,
|
||||
preflight_token.as_deref().ok_or("ETCD_PREFLIGHT_REQUIRED: Request a preflight confirmation")?,
|
||||
confirmation_text.as_deref().ok_or("ETCD_PREFLIGHT_REQUIRED: Request a preflight confirmation")?,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
dbx_core::agent_kv::etcd_auth_call_core(&state, &connection_id, method, params).await
|
||||
}
|
||||
|
||||
fn auth_preflight_action(operation: &str) -> Option<&'static str> {
|
||||
match operation {
|
||||
"user_add" => Some("auth_user_add"),
|
||||
"user_delete" => Some("auth_user_delete"),
|
||||
"user_change_password" => Some("auth_user_change_password"),
|
||||
"user_grant_role" => Some("auth_user_grant_role"),
|
||||
"user_revoke_role" => Some("auth_user_revoke_role"),
|
||||
"role_add" => Some("auth_role_add"),
|
||||
"role_delete" => Some("auth_role_delete"),
|
||||
"role_grant_permission" => Some("auth_role_grant_permission"),
|
||||
"role_revoke_permission" => Some("auth_role_revoke_permission"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user