refactor: centralize iam runtime source helpers (#3828)

This commit is contained in:
Zhengchao An
2026-06-24 22:49:24 +08:00
committed by GitHub
parent a935854b32
commit ad6184b126
6 changed files with 68 additions and 25 deletions
+10 -11
View File
@@ -26,9 +26,7 @@ use rustfs_ecstore::api::error::{
classify_system_path_failure_reason as ecstore_classify_system_path_failure_reason,
};
use rustfs_ecstore::api::global::is_first_cluster_node_local as ecstore_is_first_cluster_node_local;
use rustfs_ecstore::api::notification::{
NotificationPeerErr as EcstoreNotificationPeerErr, get_global_notification_sys as ecstore_get_global_notification_sys,
};
use rustfs_ecstore::api::notification::NotificationPeerErr as EcstoreNotificationPeerErr;
use rustfs_ecstore::api::storage::ECStore as EcstoreStore;
use std::sync::{Arc, OnceLock};
use store::object::ObjectStore;
@@ -48,6 +46,7 @@ pub mod manager;
pub mod oidc;
pub mod oidc_state;
mod root_credentials;
mod runtime_sources;
mod server_config;
pub mod store;
pub mod sys;
@@ -114,7 +113,7 @@ impl From<EcstoreNotificationPeerErr> for IamNotificationPeerErr {
}
pub(crate) async fn notify_iam_delete_policy(policy_name: &str) -> Vec<IamNotificationPeerErr> {
match ecstore_get_global_notification_sys() {
match runtime_sources::notification_sys() {
Some(notification_sys) => notification_sys
.delete_policy(policy_name)
.await
@@ -126,7 +125,7 @@ pub(crate) async fn notify_iam_delete_policy(policy_name: &str) -> Vec<IamNotifi
}
pub(crate) async fn notify_iam_load_policy(policy_name: &str) -> Vec<IamNotificationPeerErr> {
match ecstore_get_global_notification_sys() {
match runtime_sources::notification_sys() {
Some(notification_sys) => notification_sys
.load_policy(policy_name)
.await
@@ -138,7 +137,7 @@ pub(crate) async fn notify_iam_load_policy(policy_name: &str) -> Vec<IamNotifica
}
pub(crate) async fn notify_iam_delete_user(access_key: &str) -> Vec<IamNotificationPeerErr> {
match ecstore_get_global_notification_sys() {
match runtime_sources::notification_sys() {
Some(notification_sys) => notification_sys
.delete_user(access_key)
.await
@@ -150,7 +149,7 @@ pub(crate) async fn notify_iam_delete_user(access_key: &str) -> Vec<IamNotificat
}
pub(crate) async fn notify_iam_load_user(access_key: &str, temp: bool) -> Vec<IamNotificationPeerErr> {
match ecstore_get_global_notification_sys() {
match runtime_sources::notification_sys() {
Some(notification_sys) => notification_sys
.load_user(access_key, temp)
.await
@@ -162,7 +161,7 @@ pub(crate) async fn notify_iam_load_user(access_key: &str, temp: bool) -> Vec<Ia
}
pub(crate) async fn notify_iam_load_service_account(access_key: &str) -> Vec<IamNotificationPeerErr> {
match ecstore_get_global_notification_sys() {
match runtime_sources::notification_sys() {
Some(notification_sys) => notification_sys
.load_service_account(access_key)
.await
@@ -174,7 +173,7 @@ pub(crate) async fn notify_iam_load_service_account(access_key: &str) -> Vec<Iam
}
pub(crate) async fn notify_iam_delete_service_account(access_key: &str) -> Vec<IamNotificationPeerErr> {
match ecstore_get_global_notification_sys() {
match runtime_sources::notification_sys() {
Some(notification_sys) => notification_sys
.delete_service_account(access_key)
.await
@@ -186,7 +185,7 @@ pub(crate) async fn notify_iam_delete_service_account(access_key: &str) -> Vec<I
}
pub(crate) async fn notify_iam_load_group(group: &str) -> Vec<IamNotificationPeerErr> {
match ecstore_get_global_notification_sys() {
match runtime_sources::notification_sys() {
Some(notification_sys) => notification_sys.load_group(group).await.into_iter().map(Into::into).collect(),
None => Vec::new(),
}
@@ -197,7 +196,7 @@ pub(crate) async fn notify_iam_load_policy_mapping(
user_type: u64,
is_group: bool,
) -> Vec<IamNotificationPeerErr> {
match ecstore_get_global_notification_sys() {
match runtime_sources::notification_sys() {
Some(notification_sys) => notification_sys
.load_policy_mapping(user_or_group, user_type, is_group)
.await
+2 -2
View File
@@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use rustfs_credentials::{Credentials, get_global_action_cred};
use rustfs_credentials::Credentials;
pub(crate) fn credentials() -> Option<Credentials> {
get_global_action_cred()
crate::runtime_sources::action_credentials()
}
pub(crate) fn credentials_or_default() -> Credentials {
+29
View File
@@ -0,0 +1,29 @@
// Copyright 2024 RustFS Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use rustfs_config::server_config::{Config as ServerConfig, get_global_server_config};
use rustfs_credentials::{Credentials, get_global_action_cred};
use rustfs_ecstore::api::notification::{NotificationSys, get_global_notification_sys};
pub(crate) fn action_credentials() -> Option<Credentials> {
get_global_action_cred()
}
pub(crate) fn current_server_config() -> Option<ServerConfig> {
get_global_server_config()
}
pub(crate) fn notification_sys() -> Option<&'static NotificationSys> {
get_global_notification_sys()
}
+2 -2
View File
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use rustfs_config::server_config::{Config as ServerConfig, get_global_server_config};
use rustfs_config::server_config::Config as ServerConfig;
pub(crate) fn current_server_config() -> Option<ServerConfig> {
get_global_server_config()
crate::runtime_sources::current_server_config()
}