test accountinfo

This commit is contained in:
weisd
2024-11-12 17:38:36 +08:00
parent 47ade0f135
commit b400860538
8 changed files with 102 additions and 26 deletions
+1
View File
@@ -21,3 +21,4 @@ quick-xml = "0.37.0"
serde-xml-rs = "0.6.0"
ecstore.workspace = true
time.workspace = true
serde_json.workspace = true
+62 -4
View File
@@ -1,16 +1,24 @@
use std::collections::HashSet;
use crate::router::Operation;
use ecstore::bucket::policy::action::{Action, ActionSet};
use ecstore::bucket::policy::bucket_policy::{BPStatement, BucketPolicy};
use ecstore::bucket::policy::effect::Effect;
use ecstore::bucket::policy::resource::{Resource, ResourceSet};
use ecstore::store_api::StorageAPI;
use ecstore::utils::xml;
use ecstore::{new_object_layer_fn, store_api::BackendInfo};
use hyper::StatusCode;
use matchit::Params;
use s3s::S3ErrorCode;
use s3s::{
dto::{AssumeRoleOutput, Credentials, Timestamp},
s3_error, Body, S3Request, S3Response, S3Result,
s3_error, Body, S3Error, S3Request, S3Response, S3Result,
};
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use serde_urlencoded::from_bytes;
use time::{Duration, OffsetDateTime};
use tracing::warn;
#[derive(Deserialize, Debug, Default)]
#[serde(rename_all = "PascalCase", default)]
pub struct AssumeRoleRequest {
@@ -88,6 +96,14 @@ impl Operation for AssumeRoleHandle {
}
}
#[derive(Debug, Serialize, Default)]
#[serde(rename_all = "PascalCase", default)]
pub struct AccountInfo {
pub account_name: String,
pub server: BackendInfo,
pub policy: BucketPolicy,
}
pub struct AccountInfoHandler {}
#[async_trait::async_trait]
impl Operation for AccountInfoHandler {
@@ -98,7 +114,49 @@ impl Operation for AccountInfoHandler {
warn!("AccountInfoHandler cread {:?}", &cred);
return Err(s3_error!(NotImplemented));
let layer = new_object_layer_fn();
let lock = layer.read().await;
let store = match lock.as_ref() {
Some(s) => s,
None => return Err(S3Error::with_message(S3ErrorCode::InternalError, "Not init".to_string())),
};
// test policy
let mut s3_all_act = HashSet::with_capacity(1);
s3_all_act.insert(Action::AllActions);
let mut all_res = HashSet::with_capacity(1);
all_res.insert(Resource::new("*"));
let bucket_policy = BucketPolicy {
id: "".to_owned(),
version: "2012-10-17".to_owned(),
statements: vec![BPStatement {
sid: "".to_owned(),
effect: Effect::Allow,
actions: ActionSet(s3_all_act),
resources: ResourceSet(all_res),
..Default::default()
}],
};
// let policy = bucket_policy
// .marshal_msg()
// .map_err(|_e| S3Error::with_message(S3ErrorCode::InternalError, "parse policy failed"))?;
let backend_info = store.backend_info().await;
let info = AccountInfo {
account_name: cred.access_key,
server: backend_info,
policy: bucket_policy,
};
let output = serde_json::to_string(&info)
.map_err(|_e| S3Error::with_message(S3ErrorCode::InternalError, "parse accountInfo failed"))?;
Ok(S3Response::new((StatusCode::OK, Body::from(output))))
}
}