mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-10 23:26:53 +00:00
init AssumeRoleHandle
This commit is contained in:
+59
-43
@@ -1,9 +1,14 @@
|
||||
use crate::router::Operation;
|
||||
use ecstore::utils::xml;
|
||||
use hyper::StatusCode;
|
||||
use matchit::Params;
|
||||
use s3s::{s3_error, Body, S3Request, S3Response, S3Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use s3s::{
|
||||
dto::{AssumeRoleOutput, Credentials, Timestamp},
|
||||
s3_error, Body, S3Request, S3Response, S3Result,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_urlencoded::from_bytes;
|
||||
use time::{Duration, OffsetDateTime};
|
||||
use tracing::warn;
|
||||
|
||||
#[derive(Deserialize, Debug, Default)]
|
||||
@@ -18,31 +23,31 @@ pub struct AssumeRoleRequest {
|
||||
pub external_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Default)]
|
||||
#[serde(rename_all = "PascalCase", default)]
|
||||
pub struct AssumeRoleResponse {
|
||||
#[serde(rename = "AssumeRoleResult")]
|
||||
pub result: AssumeRoleResult,
|
||||
}
|
||||
// #[derive(Debug, Serialize, Default)]
|
||||
// #[serde(rename_all = "PascalCase", default)]
|
||||
// pub struct AssumeRoleResponse {
|
||||
// #[serde(rename = "AssumeRoleResult")]
|
||||
// pub result: AssumeRoleResult,
|
||||
// }
|
||||
|
||||
#[derive(Debug, Serialize, Default)]
|
||||
#[serde(rename_all = "PascalCase", default)]
|
||||
pub struct AssumeRoleResult {
|
||||
pub credentials: Credentials,
|
||||
}
|
||||
// #[derive(Debug, Serialize, Default)]
|
||||
// #[serde(rename_all = "PascalCase", default)]
|
||||
// pub struct AssumeRoleResult {
|
||||
// pub credentials: Credentials,
|
||||
// }
|
||||
|
||||
#[derive(Debug, Serialize, Default)]
|
||||
#[serde(rename_all = "PascalCase", default)]
|
||||
pub struct Credentials {
|
||||
#[serde(rename = "AccessKeyId")]
|
||||
pub access_key: String,
|
||||
#[serde(rename = "SecretAccessKey")]
|
||||
pub secret_key: String,
|
||||
pub status: String,
|
||||
pub expiration: usize,
|
||||
pub session_token: String,
|
||||
pub parent_user: String,
|
||||
}
|
||||
// #[derive(Debug, Serialize, Default)]
|
||||
// #[serde(rename_all = "PascalCase", default)]
|
||||
// pub struct Credentials {
|
||||
// #[serde(rename = "AccessKeyId")]
|
||||
// pub access_key: String,
|
||||
// #[serde(rename = "SecretAccessKey")]
|
||||
// pub secret_key: String,
|
||||
// pub status: String,
|
||||
// pub expiration: usize,
|
||||
// pub session_token: String,
|
||||
// pub parent_user: String,
|
||||
// }
|
||||
|
||||
pub struct AssumeRoleHandle {}
|
||||
#[async_trait::async_trait]
|
||||
@@ -50,9 +55,7 @@ impl Operation for AssumeRoleHandle {
|
||||
async fn call(&self, req: S3Request<Body>, _params: Params<'_, '_>) -> S3Result<S3Response<(StatusCode, Body)>> {
|
||||
warn!("handle AssumeRoleHandle");
|
||||
|
||||
let Some(cred) = req.credentials else { return Err(s3_error!(InvalidRequest, "get body failed")) };
|
||||
|
||||
warn!("AssumeRole get cred {:?}", cred);
|
||||
let Some(cred) = req.credentials else { return Err(s3_error!(InvalidRequest, "get cred failed")) };
|
||||
|
||||
let mut input = req.input;
|
||||
|
||||
@@ -63,22 +66,21 @@ impl Operation for AssumeRoleHandle {
|
||||
|
||||
warn!("AssumeRole get body {:?}", body);
|
||||
|
||||
let resp = AssumeRoleResponse {
|
||||
result: AssumeRoleResult {
|
||||
credentials: Credentials {
|
||||
access_key: "test".to_owned(),
|
||||
secret_key: "test".to_owned(),
|
||||
status: "on".to_owned(),
|
||||
expiration: 0,
|
||||
session_token: "sdf".to_owned(),
|
||||
parent_user: cred.access_key,
|
||||
},
|
||||
},
|
||||
};
|
||||
// getAssumeRoleCredentials
|
||||
let output = serde_xml_rs::to_string(&resp).unwrap();
|
||||
let exp = OffsetDateTime::now_utc().saturating_add(Duration::days(1));
|
||||
|
||||
warn!("output {:?}", output);
|
||||
// TODO: create tmp access_key
|
||||
let resp = AssumeRoleOutput {
|
||||
credentials: Some(Credentials {
|
||||
access_key_id: cred.access_key,
|
||||
expiration: Timestamp::from(exp),
|
||||
secret_access_key: cred.secret_key.expose().to_string(),
|
||||
session_token: "sdfsdf".to_owned(),
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// getAssumeRoleCredentials
|
||||
let output = xml::serialize::<AssumeRoleOutput>(&resp).unwrap();
|
||||
|
||||
Ok(S3Response::new((StatusCode::OK, Body::from(output))))
|
||||
|
||||
@@ -86,6 +88,20 @@ impl Operation for AssumeRoleHandle {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AccountInfoHandler {}
|
||||
#[async_trait::async_trait]
|
||||
impl Operation for AccountInfoHandler {
|
||||
async fn call(&self, req: S3Request<Body>, _params: Params<'_, '_>) -> S3Result<S3Response<(StatusCode, Body)>> {
|
||||
warn!("handle AccountInfoHandler");
|
||||
|
||||
let Some(cred) = req.credentials else { return Err(s3_error!(InvalidRequest, "get cred failed")) };
|
||||
|
||||
warn!("AccountInfoHandler cread {:?}", &cred);
|
||||
|
||||
return Err(s3_error!(NotImplemented));
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ServiceHandle {}
|
||||
#[async_trait::async_trait]
|
||||
impl Operation for ServiceHandle {
|
||||
|
||||
+5
-1
@@ -12,7 +12,11 @@ pub fn make_admin_route() -> Result<impl S3Route> {
|
||||
let mut r = S3Router::new();
|
||||
|
||||
r.insert(Method::POST, "/", AdminOperation(&handlers::AssumeRoleHandle {}))?;
|
||||
|
||||
r.insert(
|
||||
Method::GET,
|
||||
format!("{}{}", ADMIN_PREFIX, "/v3/accountinfo").as_str(),
|
||||
AdminOperation(&handlers::AccountInfoHandler {}),
|
||||
)?;
|
||||
r.insert(
|
||||
Method::POST,
|
||||
format!("{}{}", ADMIN_PREFIX, "/v3/service").as_str(),
|
||||
|
||||
Reference in New Issue
Block a user