-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,180 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use crate::ops::Operations; | ||
|
||
use codegen_writer::g; | ||
use codegen_writer::glines; | ||
use heck::ToSnakeCase; | ||
|
||
pub fn codegen(ops: &Operations) { | ||
glines![ | ||
"//! Auto generated by `codegen/src/access.rs`" | ||
"use super::S3AccessContext;" | ||
"" | ||
"use crate::dto::*;" | ||
"use crate::error::S3Result;" | ||
"use crate::request::S3Request;" | ||
"" | ||
"#[async_trait::async_trait]" | ||
"pub trait S3Access: Send + Sync + 'static {" | ||
"" | ||
]; | ||
|
||
glines![ | ||
"/// Checks whether the current request has accesses to the resources." | ||
"///" | ||
"/// This method is called before deserializing the operation input." | ||
"///" | ||
"/// By default, this method rejects all anonymous requests" | ||
"/// and returns [`AccessDenied`](crate::S3ErrorCode::AccessDenied) error." | ||
"///" | ||
"/// An access control provider can override this method to implement custom logic." | ||
"///" | ||
"/// Common fields in the context:" | ||
"/// + [`cx.credentials()`](S3AccessContext::credentials)" | ||
"/// + [`cx.s3_path()`](S3AccessContext::s3_path)" | ||
"/// + [`cx.s3_op().name()`](crate::S3Operation::name)" | ||
"/// + [`cx.extensions_mut()`](S3AccessContext::extensions_mut)" | ||
"async fn check(&self, cx: &mut S3AccessContext<'_>) -> S3Result<()> {" | ||
" super::default_check(cx)" | ||
"}" | ||
]; | ||
|
||
for op in ops.values() { | ||
let method_name = op.name.to_snake_case(); | ||
let input = &op.input; | ||
|
||
g!("/// Checks whether the {} request has accesses to the resources.", op.name); | ||
g!("/// "); | ||
g!("/// This method returns `Ok(())` by default."); | ||
g!("async fn {method_name}(&self, _req: &mut S3Request<{input}>) -> S3Result<()> {{"); | ||
g!("Ok(())"); | ||
g!("}}"); | ||
g!(); | ||
} | ||
|
||
g!("}}"); | ||
g!(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.