Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: include readme into crates documentation #100

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

[`actix-web`]: https://github.com/actix/actix-web

[`axum`]:https://github.com/tokio-rs/axum
[`axum`]: https://github.com/tokio-rs/axum

[`poem`]: https://github.com/poem-web/poem

Expand Down
2 changes: 2 additions & 0 deletions core/src/authorities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ pub mod extractor;

pub use attache::AttachAuthorities;

/// Trait to check if the user has the required authorities.
pub trait AuthoritiesCheck<T: Eq + Hash> {
fn has_authority(&self, authority: T) -> bool;
fn has_authorities(&self, authorities: &[T]) -> bool;
fn has_any_authority(&self, authorities: &[T]) -> bool;
}

/// Storage for user authorities to keep them as an extension of request.
pub struct AuthDetails<T = String>
where
T: Eq + Hash,
Expand Down
3 changes: 3 additions & 0 deletions core/src/authorities/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use std::collections::HashSet;
use std::future::Future;
use std::hash::Hash;

/// Trait for extracting authorities from the request.
/// By default, is implemented for functions with signature `fn(&mut Request) -> Result<HashSet<Type>, Into<Response>`.
/// But can be implemented for custom structures and enums.
pub trait AuthoritiesExtractor<'a, Request, Type, Error> {
type Future: Future<Output = Result<HashSet<Type>, Error>> + Send;

Expand Down
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod authorities;

#[cfg(feature = "tower")]
#[cfg_attr(docsrs, doc(cfg(feature = "tower")))]
pub mod tower;
1 change: 1 addition & 0 deletions core/src/tower/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::task::{Context, Poll};
use std::{future::Future, pin::Pin};
use tower::{Layer, Service};

/// Tower compatible middleware for attaching custom authorities to the request (based on [`AuthoritiesExtractor`]).
pub struct GrantsLayer<Extractor, Request, Type, Err> {
extractor: Arc<Extractor>,
phantom_req: PhantomData<Request>,
Expand Down
14 changes: 14 additions & 0 deletions protect-axum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#![doc(
html_logo_url = "https://raw.githubusercontent.com/DDtKey/protect-endpoints/main/protect-axum/logo.png"
)]
//! A crate to protect your endpoints in [`axum`].
//!
//! For built-in configuration, you can use [`GrantsLayer`] tower compatible middleware.
//!
//! To check user access to specific services, you can use [`proc-macro`] or manual.
//!
//! [`permissions`]: authorities
//! [`proc-macro`]: proc_macro
//! [`axum`]: https://github.com/tokio-rs/axum
#![doc = include_str!("../README.md")]

use protect_endpoints_core::tower::middleware::GrantsLayer as CoreGrantsLayer;

pub mod authorities;
Expand Down
2 changes: 1 addition & 1 deletion protect-salvo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ You can find more [`examples`] in the git repository folder and [`documentation`

[`documentation`]: https://docs.rs/protect-salvo

[`salvo`]: https://salvo.rs/
[`salvo`]: https://github.com/salvo-rs/salvo
14 changes: 14 additions & 0 deletions protect-salvo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#![doc(
html_logo_url = "https://raw.githubusercontent.com/DDtKey/protect-endpoints/main/protect-salvo/logo.png"
)]
//! A crate to protect your endpoints in [`salvo`].
//!
//! For built-in configuration, you can use [`GrantsLayer`] tower compatible middleware.
//!
//! To check user access to specific services, you can use [`proc-macro`] or manual.
//!
//! [`permissions`]: authorities
//! [`proc-macro`]: proc_macro
//! [`salvo`]: https://github.com/salvo-rs/salvo
#![doc = include_str!("../README.md")]

use protect_endpoints_core::tower::middleware::GrantsLayer as CoreGrantsLayer;
use salvo::http::ReqBody;

Expand Down
Loading