mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-18 18:46:17 +00:00
refactor(admin): route kms handlers through app context (#1967)
Signed-off-by: 安正超 <anzhengchao@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -17,11 +17,12 @@
|
|||||||
use super::{kms_dynamic, kms_keys, kms_management};
|
use super::{kms_dynamic, kms_keys, kms_management};
|
||||||
use crate::admin::auth::validate_admin_request;
|
use crate::admin::auth::validate_admin_request;
|
||||||
use crate::admin::router::{AdminOperation, Operation, S3Router};
|
use crate::admin::router::{AdminOperation, Operation, S3Router};
|
||||||
|
use crate::app::context::resolve_kms_runtime_service_manager;
|
||||||
use crate::auth::{check_key_valid, get_session_token};
|
use crate::auth::{check_key_valid, get_session_token};
|
||||||
use crate::server::RemoteAddr;
|
use crate::server::RemoteAddr;
|
||||||
use hyper::{HeaderMap, StatusCode};
|
use hyper::{HeaderMap, StatusCode};
|
||||||
use matchit::Params;
|
use matchit::Params;
|
||||||
use rustfs_kms::get_global_encryption_service;
|
use rustfs_kms::init_global_kms_service_manager;
|
||||||
use rustfs_policy::policy::action::{Action, AdminAction};
|
use rustfs_policy::policy::action::{Action, AdminAction};
|
||||||
use s3s::header::CONTENT_TYPE;
|
use s3s::header::CONTENT_TYPE;
|
||||||
use s3s::{Body, S3Request, S3Response, S3Result, s3_error};
|
use s3s::{Body, S3Request, S3Response, S3Result, s3_error};
|
||||||
@@ -29,6 +30,17 @@ use serde::{Deserialize, Serialize};
|
|||||||
use serde_json;
|
use serde_json;
|
||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
|
|
||||||
|
async fn kms_encryption_service_from_context() -> Option<std::sync::Arc<rustfs_kms::ObjectEncryptionService>> {
|
||||||
|
let manager = match resolve_kms_runtime_service_manager() {
|
||||||
|
Some(manager) => manager,
|
||||||
|
None => {
|
||||||
|
warn!("KMS service manager not initialized, initializing now as fallback");
|
||||||
|
init_global_kms_service_manager()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
manager.get_encryption_service().await
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct KmsStatusResponse {
|
pub struct KmsStatusResponse {
|
||||||
pub backend_type: String,
|
pub backend_type: String,
|
||||||
@@ -83,7 +95,7 @@ impl Operation for KmsStatusHandler {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let Some(service) = get_global_encryption_service().await else {
|
let Some(service) = kms_encryption_service_from_context().await else {
|
||||||
return Err(s3_error!(InternalError, "KMS service not initialized"));
|
return Err(s3_error!(InternalError, "KMS service not initialized"));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -141,7 +153,7 @@ impl Operation for KmsConfigHandler {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let Some(service) = get_global_encryption_service().await else {
|
let Some(service) = kms_encryption_service_from_context().await else {
|
||||||
return Err(s3_error!(InternalError, "KMS service not initialized"));
|
return Err(s3_error!(InternalError, "KMS service not initialized"));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -186,7 +198,7 @@ impl Operation for KmsClearCacheHandler {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let Some(service) = get_global_encryption_service().await else {
|
let Some(service) = kms_encryption_service_from_context().await else {
|
||||||
return Err(s3_error!(InternalError, "KMS service not initialized"));
|
return Err(s3_error!(InternalError, "KMS service not initialized"));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user