feat(nacos): add access control support
This commit is contained in:
67 files changed
+9062
-135
No files matched your search
@@ -723,6 +723,7 @@ async fn main() {
|
||||
// Nacos
|
||||
.route("/nacos/test-connection", post(routes::nacos::test_connection))
|
||||
.route("/nacos/namespaces/list", post(routes::nacos::list_namespaces))
|
||||
.route("/nacos/sidebar/snapshot", post(routes::nacos::sidebar_snapshot))
|
||||
.route("/nacos/namespaces/create", post(routes::nacos::create_namespace))
|
||||
.route("/nacos/namespaces/update", post(routes::nacos::update_namespace))
|
||||
.route("/nacos/configs/list", post(routes::nacos::list_configs))
|
||||
@@ -734,6 +735,18 @@ async fn main() {
|
||||
.route("/nacos/configs/history/rollback", post(routes::nacos::rollback_config))
|
||||
.route("/nacos/rnacos-console/captcha", post(routes::nacos::get_rnacos_console_captcha))
|
||||
.route("/nacos/rnacos-console/login", post(routes::nacos::login_rnacos_console))
|
||||
.route("/nacos/users/list", post(routes::nacos::list_users))
|
||||
.route("/nacos/users/create", post(routes::nacos::create_user))
|
||||
.route("/nacos/users/update", post(routes::nacos::update_user))
|
||||
.route("/nacos/users/delete", post(routes::nacos::delete_user))
|
||||
.route("/nacos/roles/list", post(routes::nacos::list_role_bindings))
|
||||
.route("/nacos/roles/assign", post(routes::nacos::assign_role))
|
||||
.route("/nacos/roles/remove", post(routes::nacos::remove_role))
|
||||
.route("/nacos/access/snapshot", post(routes::nacos::access_snapshot))
|
||||
.route("/nacos/access/operations/start", post(routes::nacos::start_access_operation))
|
||||
.route("/nacos/access/operations/get", post(routes::nacos::get_access_operation))
|
||||
.route("/nacos/access/operations/retry", post(routes::nacos::retry_access_operation))
|
||||
.route("/nacos/access/operations/undo", post(routes::nacos::undo_access_operation))
|
||||
.route("/nacos/services/list", post(routes::nacos::list_services))
|
||||
.route("/nacos/services/get", post(routes::nacos::get_service))
|
||||
.route("/nacos/services/create", post(routes::nacos::create_service))
|
||||
|
||||
@@ -179,8 +179,18 @@ async fn run_temporary_connection_test(
|
||||
let temp_id = format!("{TEST_PROBE_ID_PREFIX}{}", uuid::Uuid::new_v4());
|
||||
app.configs.write().await.insert(temp_id.clone(), config.clone());
|
||||
|
||||
let pool_result = app.get_or_create_pool(&temp_id, config.database.as_deref()).await;
|
||||
let database_info = if include_database_info {
|
||||
let pool_result = if config.db_type == DatabaseType::Nacos {
|
||||
match app.nacos_admin_config_for_connection(&temp_id, &config).await {
|
||||
Ok(admin_config) => match app.nacos_registry.build_transient_config(admin_config).await {
|
||||
Ok(adapter) => adapter.test_connection_with_scope_validation().await.map(|_| temp_id.clone()),
|
||||
Err(error) => Err(error),
|
||||
},
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
} else {
|
||||
app.get_or_create_pool(&temp_id, config.database.as_deref()).await
|
||||
};
|
||||
let database_info = if include_database_info && config.db_type != DatabaseType::Nacos {
|
||||
match &pool_result {
|
||||
Ok(_) => match app.connection_database_info(&temp_id, config.database.as_deref()).await {
|
||||
Ok(info) => info,
|
||||
@@ -299,6 +309,7 @@ pub async fn connect_db(
|
||||
}
|
||||
|
||||
app.remove_connection_pools_detached(&connection_id).await;
|
||||
app.nacos_registry.drop_connection(&connection_id).await;
|
||||
app.reset_connection_transport_for_config(&connection_id, &runtime_config).await;
|
||||
app.configs.write().await.insert(connection_id.clone(), runtime_config);
|
||||
|
||||
|
||||
@@ -88,6 +88,69 @@ pub(crate) struct RNacosConsoleLoginReq {
|
||||
captcha: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct UserListReq {
|
||||
connection_id: String,
|
||||
query: dbx_core::nacos::NacosUserQuery,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct UserCreateReq {
|
||||
connection_id: String,
|
||||
req: dbx_core::nacos::NacosUserCreate,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct UserUpdateReq {
|
||||
connection_id: String,
|
||||
req: dbx_core::nacos::NacosUserUpdate,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct UserDeleteReq {
|
||||
connection_id: String,
|
||||
username: String,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct RoleListReq {
|
||||
connection_id: String,
|
||||
query: dbx_core::nacos::NacosRoleQuery,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct RoleBindingReq {
|
||||
connection_id: String,
|
||||
binding: dbx_core::nacos::NacosRoleBinding,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct AccessOperationReq {
|
||||
connection_id: String,
|
||||
req: dbx_core::nacos::NacosAccessOperationRequest,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct AccessOperationIdReq {
|
||||
connection_id: String,
|
||||
operation_id: String,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct AccessOperationRetryReq {
|
||||
connection_id: String,
|
||||
retry: dbx_core::nacos::NacosAccessOperationRetry,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub(crate) struct ServiceListReq {
|
||||
@@ -217,6 +280,16 @@ pub async fn list_namespaces(
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn sidebar_snapshot(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<ConnReq>,
|
||||
) -> Result<Json<dbx_core::nacos::NacosNamespaceSidebarSnapshot>, AppError> {
|
||||
let result = dbx_core::nacos::service::nacos_sidebar_snapshot_core(&state.app, &req.connection_id)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn create_namespace(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<NamespaceCreateReq>,
|
||||
@@ -327,6 +400,128 @@ pub async fn login_rnacos_console(
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
pub async fn list_users(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<UserListReq>,
|
||||
) -> Result<Json<dbx_core::nacos::NacosUserList>, AppError> {
|
||||
let result = dbx_core::nacos::service::nacos_list_users_core(&state.app, &req.connection_id, req.query)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn create_user(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<UserCreateReq>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
dbx_core::nacos::service::nacos_create_user_core(&state.app, &req.connection_id, req.req)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
pub async fn update_user(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<UserUpdateReq>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
dbx_core::nacos::service::nacos_update_user_core(&state.app, &req.connection_id, req.req)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
pub async fn delete_user(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<UserDeleteReq>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
dbx_core::nacos::service::nacos_delete_user_core(&state.app, &req.connection_id, req.username)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
pub async fn list_role_bindings(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RoleListReq>,
|
||||
) -> Result<Json<dbx_core::nacos::NacosRoleList>, AppError> {
|
||||
let result = dbx_core::nacos::service::nacos_list_role_bindings_core(&state.app, &req.connection_id, req.query)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn assign_role(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RoleBindingReq>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
dbx_core::nacos::service::nacos_assign_role_core(&state.app, &req.connection_id, req.binding)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
pub async fn remove_role(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<RoleBindingReq>,
|
||||
) -> Result<Json<()>, AppError> {
|
||||
dbx_core::nacos::service::nacos_remove_role_core(&state.app, &req.connection_id, req.binding)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(()))
|
||||
}
|
||||
|
||||
pub async fn access_snapshot(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<ConnReq>,
|
||||
) -> Result<Json<dbx_core::nacos::NacosAccessControlSnapshot>, AppError> {
|
||||
let result = dbx_core::nacos::service::nacos_access_snapshot_core(&state.app, &req.connection_id)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn start_access_operation(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<AccessOperationReq>,
|
||||
) -> Result<Json<dbx_core::nacos::NacosAccessOperationResult>, AppError> {
|
||||
let result = dbx_core::nacos::service::nacos_start_access_operation_core(&state.app, &req.connection_id, req.req)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn get_access_operation(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<AccessOperationIdReq>,
|
||||
) -> Result<Json<dbx_core::nacos::NacosAccessOperationResult>, AppError> {
|
||||
let result =
|
||||
dbx_core::nacos::service::nacos_get_access_operation_core(&state.app, &req.connection_id, &req.operation_id)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn retry_access_operation(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<AccessOperationRetryReq>,
|
||||
) -> Result<Json<dbx_core::nacos::NacosAccessOperationResult>, AppError> {
|
||||
let result = dbx_core::nacos::service::nacos_retry_access_operation_core(&state.app, &req.connection_id, req.retry)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn undo_access_operation(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<AccessOperationIdReq>,
|
||||
) -> Result<Json<dbx_core::nacos::NacosAccessOperationResult>, AppError> {
|
||||
let result =
|
||||
dbx_core::nacos::service::nacos_undo_access_operation_core(&state.app, &req.connection_id, &req.operation_id)
|
||||
.await
|
||||
.map_err(AppError::from)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
pub async fn list_services(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(req): Json<ServiceListReq>,
|
||||
|
||||
Reference in new issue
Block a user