Skip to content

Commit

Permalink
spi-object:fix special
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed May 31, 2024
1 parent 19b2bac commit 867ef00
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 11 deletions.
66 changes: 60 additions & 6 deletions backend/spi/spi-object/src/api/ci/object_ci_obj_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,79 @@ pub struct ObjectCiObjApi;
impl ObjectCiObjApi {
/// Fetch URL for temporary authorization of file upload
#[oai(path = "/presign/put", method = "get")]
async fn presign_put_obj_url(&self, object_path: Query<String>, exp_secs: Query<u32>, private: Query<bool>, ctx: TardisContextExtractor) -> TardisApiResult<String> {
async fn presign_put_obj_url(
&self,
object_path: Query<String>,
exp_secs: Query<u32>,
private: Query<Option<bool>>,
special: Query<Option<bool>>,
ctx: TardisContextExtractor,
) -> TardisApiResult<String> {
let funs = crate::get_tardis_inst();
let url = object_obj_serv::presign_obj_url(ObjectObjPresignKind::Upload, object_path.0.trim(), None, None, exp_secs.0, private.0, &funs, &ctx.0).await?;
let url = object_obj_serv::presign_obj_url(
ObjectObjPresignKind::Upload,
object_path.0.trim(),
None,
None,
exp_secs.0,
private.0,
special.0,
&funs,
&ctx.0,
)
.await?;
TardisResp::ok(url)
}

/// Fetch URL for temporary authorization of file delete
#[oai(path = "/presign/delete", method = "get")]
async fn presign_delete_obj_url(&self, object_path: Query<String>, exp_secs: Query<u32>, private: Query<bool>, ctx: TardisContextExtractor) -> TardisApiResult<String> {
async fn presign_delete_obj_url(
&self,
object_path: Query<String>,
exp_secs: Query<u32>,
private: Query<Option<bool>>,
special: Query<Option<bool>>,
ctx: TardisContextExtractor,
) -> TardisApiResult<String> {
let funs = crate::get_tardis_inst();
let url = object_obj_serv::presign_obj_url(ObjectObjPresignKind::Delete, object_path.0.trim(), None, None, exp_secs.0, private.0, &funs, &ctx.0).await?;
let url = object_obj_serv::presign_obj_url(
ObjectObjPresignKind::Delete,
object_path.0.trim(),
None,
None,
exp_secs.0,
private.0,
special.0,
&funs,
&ctx.0,
)
.await?;
TardisResp::ok(url)
}

/// Fetch URL for temporary authorization of file
#[oai(path = "/presign/view", method = "get")]
async fn presign_view_obj_url(&self, object_path: Query<String>, exp_secs: Query<u32>, private: Query<bool>, ctx: TardisContextExtractor) -> TardisApiResult<String> {
async fn presign_view_obj_url(
&self,
object_path: Query<String>,
exp_secs: Query<u32>,
private: Query<Option<bool>>,
special: Query<Option<bool>>,
ctx: TardisContextExtractor,
) -> TardisApiResult<String> {
let funs = crate::get_tardis_inst();
let url = object_obj_serv::presign_obj_url(ObjectObjPresignKind::View, object_path.0.trim(), None, None, exp_secs.0, private.0, &funs, &ctx.0).await?;
let url = object_obj_serv::presign_obj_url(
ObjectObjPresignKind::View,
object_path.0.trim(),
None,
None,
exp_secs.0,
private.0,
special.0,
&funs,
&ctx.0,
)
.await?;
TardisResp::ok(url)
}

Expand Down
7 changes: 5 additions & 2 deletions backend/spi/spi-object/src/serv/object_obj_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ pub async fn presign_obj_url(
max_width: Option<String>,
max_height: Option<String>,
exp_secs: u32,
private: bool,
private: Option<bool>,
special: Option<bool>,
funs: &TardisFunsInst,
ctx: &TardisContext,
) -> TardisResult<String> {
let inst = funs.init(ctx, true, object_initializer::init_fun).await?;
match inst.kind_code() {
#[cfg(feature = "spi-s3")]
object_constants::SPI_S3_KIND_CODE => s3::object_s3_obj_serv::presign_obj_url(presign_kind, object_path, max_width, max_height, exp_secs, private, funs, ctx, &inst).await,
object_constants::SPI_S3_KIND_CODE => {
s3::object_s3_obj_serv::presign_obj_url(presign_kind, object_path, max_width, max_height, exp_secs, private, special, funs, ctx, &inst).await
}
kind_code => Err(funs.bs_not_implemented(kind_code)),
}
}
9 changes: 9 additions & 0 deletions backend/spi/spi-object/src/serv/s3/object_s3_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ pub async fn init(bs_cert: &SpiBsCertResp, ctx: &TardisContext, _: bool) -> Tard
));
}
}
let resp = client.bucket_create_simple(&format!("{bucket_name_prefix}-spe"), false).await;
if let Err(e) = resp {
if e.code != "409" {
return Err(TardisError::internal_error(
&format!("Bucket {bucket_name_prefix}-spe creation failed"),
&format!("{:?}", e),
));
}
}
spi_initializer::common::set_isolation_flag_to_ext(&bucket_name_prefix, &mut ext);
};
Ok(SpiBsInst { client: Box::new(client), ext })
Expand Down
19 changes: 16 additions & 3 deletions backend/spi/spi-object/src/serv/s3/object_s3_obj_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,33 @@ pub async fn presign_obj_url(
_max_width: Option<String>,
_max_height: Option<String>,
exp_secs: u32,
private: bool,
private: Option<bool>,
special: Option<bool>,
funs: &TardisFunsInst,
ctx: &TardisContext,
inst: &SpiBsInst,
) -> TardisResult<String> {
let bs_inst = inst.inst::<TardisOSClient>();
let spi_bs = SpiBsServ::get_bs_by_rel(&ctx.ak, None, funs, ctx).await?;
let client = bs_inst.0;
let bucket_name = common::get_isolation_flag_from_ext(bs_inst.1).map(|bucket_name_prefix| format!("{}-{}", bucket_name_prefix, if private { "pri" } else { "pub" }));
let bucket_name = common::get_isolation_flag_from_ext(bs_inst.1).map(|bucket_name_prefix| {
format!(
"{}-{}",
bucket_name_prefix,
if special.unwrap_or_else(|| false) {
"spe"
} else if private.unwrap_or_else(|| true) {
"pri"
} else {
"pub"
}
)
});
match presign_kind {
ObjectObjPresignKind::Upload => client.object_create_url(object_path, exp_secs, bucket_name.as_deref()),
ObjectObjPresignKind::Delete => client.object_delete_url(object_path, exp_secs, bucket_name.as_deref()),
ObjectObjPresignKind::View => {
if private {
if private.unwrap_or_else(|| true) {
client.object_get_url(object_path, exp_secs, bucket_name.as_deref())
} else {
let Some(bucket_name) = bucket_name else {
Expand Down

0 comments on commit 867ef00

Please sign in to comment.