3个版本
0.1.2 | 2024年5月18日 |
---|---|
0.1.1 | 2023年9月17日 |
0.1.0 | 2023年9月13日 |
#933 in 网络编程
每月下载28次
用于 unftp
13KB
225 行
unftp-sbe-restrict
lib.rs
:
一个限制FTP操作的libunftp包装存储后端,同时也提供某种形式的授权。
快速开始
首先实现libunftp的UserDetail
特质,然后实现UserWithPermissions
。
最后调用RestrictingVfs::new()方法。
use libunftp::auth::UserDetail;
use unftp_sbe_restrict::{UserWithPermissions, VfsOperations};
use std::fmt::Formatter;
#[derive(Debug, PartialEq, Eq)]
pub struct User {
pub username: String,
// e.g. this can be something like
// `VfsOperations::all() - VfsOperations::PUT - VfsOperations::DEL`
pub permissions: VfsOperations,
}
impl UserDetail for User {
fn account_enabled(&self) -> bool {
true
}
}
impl std::fmt::Display for User {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "User(username: {:?}", self.username,)
}
}
impl UserWithPermissions for User {
fn permissions(&self) -> VfsOperations {
self.permissions
}
}
// Return type omited for brevity.
fn create_restricted_storage_backend() {
use unftp_sbe_fs::{Filesystem, Meta};
let _backend = Box::new(move || {
unftp_sbe_restrict::RestrictingVfs::<Filesystem, User, Meta>::new(Filesystem::new("/srv/ftp"))
});
}
依赖
~21–33MB
~575K SLoC