mirror of
https://github.com/rustfs/rustfs.git
synced 2026-09-04 11:15:39 +00:00
iam add_user
This commit is contained in:
@@ -46,6 +46,8 @@ pub enum Error {
|
|||||||
|
|
||||||
#[error("invalid access_key")]
|
#[error("invalid access_key")]
|
||||||
InvalidAccessKey,
|
InvalidAccessKey,
|
||||||
|
#[error("action not allowed")]
|
||||||
|
IAMActionNotAllowed,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|||||||
@@ -104,3 +104,8 @@ pub async fn list_users() -> crate::Result<HashMap<String, madmin::UserInfo>> {
|
|||||||
pub async fn get_user(ak: &str) -> crate::Result<(Option<UserIdentity>, bool)> {
|
pub async fn get_user(ak: &str) -> crate::Result<(Option<UserIdentity>, bool)> {
|
||||||
get()?.check_key(ak).await
|
get()?.check_key(ak).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn create_user(ak: &str, sk: &str, status: &str) -> crate::Result<OffsetDateTime> {
|
||||||
|
get()?.add_user(ak, sk, status).await
|
||||||
|
// notify
|
||||||
|
}
|
||||||
|
|||||||
+30
-2
@@ -310,7 +310,7 @@ where
|
|||||||
Ok(m)
|
Ok(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn add_user(&self, access_key: &str, secret_key: &str, status: &str) -> crate::Result<()> {
|
pub async fn add_user(&self, access_key: &str, secret_key: &str, status: &str) -> crate::Result<OffsetDateTime> {
|
||||||
let status = {
|
let status = {
|
||||||
match status {
|
match status {
|
||||||
"disabled" => auth::ACCOUNT_ON,
|
"disabled" => auth::ACCOUNT_ON,
|
||||||
@@ -319,6 +319,34 @@ where
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
todo!()
|
let users = self.cache.users.load();
|
||||||
|
if let Some(x) = users.get(access_key) {
|
||||||
|
if x.credentials.is_temp() {
|
||||||
|
return Err(crate::Error::IAMActionNotAllowed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let user_entiry = UserIdentity::from(Credentials {
|
||||||
|
access_key: access_key.to_string(),
|
||||||
|
secret_key: secret_key.to_string(),
|
||||||
|
status: status.to_string(),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
let path = format!(
|
||||||
|
"config/iam/{}{}/identity.json",
|
||||||
|
UserType::Reg.prefix(),
|
||||||
|
user_entiry.credentials.access_key
|
||||||
|
);
|
||||||
|
debug!("save object: {path:?}");
|
||||||
|
self.api.save_iam_config(&user_entiry, path).await?;
|
||||||
|
|
||||||
|
Cache::add_or_update(
|
||||||
|
&self.cache.users,
|
||||||
|
&user_entiry.credentials.access_key,
|
||||||
|
&user_entiry,
|
||||||
|
OffsetDateTime::now_utc(),
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(user_entiry.update_at.unwrap_or(OffsetDateTime::now_utc()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ pub struct AddUser {}
|
|||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl Operation for AddUser {
|
impl Operation for AddUser {
|
||||||
async fn call(&self, req: S3Request<Body>, _params: Params<'_, '_>) -> S3Result<S3Response<(StatusCode, Body)>> {
|
async fn call(&self, req: S3Request<Body>, _params: Params<'_, '_>) -> S3Result<S3Response<(StatusCode, Body)>> {
|
||||||
|
warn!("handle AddUser");
|
||||||
let query = {
|
let query = {
|
||||||
if let Some(query) = req.uri.query() {
|
if let Some(query) = req.uri.query() {
|
||||||
let input: AddUserQuery =
|
let input: AddUserQuery =
|
||||||
@@ -61,7 +62,6 @@ impl Operation for AddUser {
|
|||||||
return Err(s3_error!(InvalidArgument, "can't create user with service account access key"));
|
return Err(s3_error!(InvalidArgument, "can't create user with service account access key"));
|
||||||
}
|
}
|
||||||
|
|
||||||
warn!("handle AddUser");
|
|
||||||
return Err(s3_error!(NotImplemented));
|
return Err(s3_error!(NotImplemented));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user