当前位置:网站首页>【Rust日报】2020-05-24 Rash, Rocket, Mun, Casbin
【Rust日报】2020-05-24 Rash, Rocket, Mun, Casbin
2022-06-28 06:34:00 【51CTO】
Rash v0.1.0 released!
Rash v0.1.0 released!
https://github.com/pando85/rash
Rash是一种受Ansible工具启发的Declarative Shell脚本语言。
- 避免冗长不方便管理的Shell脚本
- 类似Ansible这样的编程风格
Declarative vs imperative:Imperative: entrypoint.sh:
#!/bin/bash
set -e
REQUIRED_PARAMS="
VAULT_URL
VAULT_ROLE_ID
VAULT_SECRET_ID
VAULT_SECRET_PATH
"
for required in $REQUIRED_PARAMS ; do
[[ -z "${!required}" ]] && echo "$required IS NOT DEFINED" && exit 1
done
echo "[$0] Logging into Vault..."
VAULT_TOKEN=$(curl -s $VAULT_URL/v1/auth/approle/login \
--data '{"role_id": "'$VAULT_ROLE_ID'","secret_id": "'$VAULT_SECRET_ID'"}' \
| jq -r .auth.client_token)
echo "[$0] Getting Samuel API key from Vault..."
export APP1_API_KEY=$(curl -s -H "X-Vault-Token: $VAULT_TOKEN" \
$VAULT_URL/v1/$VAULT_SECRET_PATH | jq -r .data.api_key)
exec "[email protected]"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
Declarative: entrypoint.rh:
#!/bin/rash
- name: Verify input parameters
assert:
that:
- VAULT_URL is defined
- VAULT_ROLE_ID is defined
- VAULT_SECRET_ID is defined
- VAULT_SECRET_PATH is defined
- name: launch docker CMD
command: {{ input.args }}
transfer_ownership: yes
env:
APP1_API_KEY: "{{ lookup('vault', env.VAULT_SECRET_PATH ) }}"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
Rocket现在可以通过stable Rust 1.45编译了。
Rocket can be compiled on stable Rust 1.45
https://github.com/SergioBenitez/Rocket/issues/19#issuecomment-630650328
Rocket现在可以通过stable Rust 1.45编译了。
Mun v0.2.0 Released
Mun v0.2.0 Released
https://github.com/mun-lang/mun/releases/tag/v0.2.0
Mun是一个通过iteration可以不断创造迭代的嵌入式编程语言。Mun语言诞生的想法来自找到一个可以规避Lua动态脚本语言的弊端有可以在Rust语言里hot-reload(热加载) 新的编程语言。因此,Mun新语言首先不能是Rust语言的竞争对手,同时有可以在Rust语言(或C/C++)宿主语言 中无缝嵌入编程。Mun完全由Rust语言写成,主要的软件包是rust-analyzer和rustc 。主要的特点包括:
- Ahead of time compilation
- Statically typed
- First class hot-reloading
新版本更新的功能:
- Hot reloadable data structures
- Marshalling of data structures to Rust, C, and C++
- Garbage collection for data structures (with opt-out at the struct-level)
- loop, while, break and explicitreturn expressions
- Full operator support for numeric and boolean types
- Incremental compilation
- Benchmark support
Actix Casbin 中间件
Actix Casbin Middleware
https://github.com/casbin-rs/actix-casbin-auth
Casbin 是Rust语言网页构架 actix-web framework的访问控制中间件。
安装(install)
在Cargo.toml添加下面的内容:
需求(requirement)
Casbin只负责权限管理,因此需要实现Authentication Middleware来确认用户。因此需要将带有subject(username)和domain(optional)信息的actix_casbin_auth::CasbinVals加在Extension里。
比如下面的例子:
use std::cell::RefCell;
use std::pin::Pin;
use std::rc::Rc;
use std::task::{Context, Poll};
use actix_service::{Service, Transform};
use actix_web::{dev::ServiceRequest, dev::ServiceResponse, Error, HttpMessage};
use futures::future::{ok, Future, Ready};
use actix_casbin_auth::CasbinVals;
pub struct FakeAuth;
impl<S: 'static, B> Transform<S> for FakeAuth
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
B: 'static,
{
type Request = ServiceRequest;
type Response = ServiceResponse<B>;
type Error = Error;
type InitError = ();
type Transform = FakeAuthMiddleware<S>;
type Future = Ready<Result<Self::Transform, Self::InitError>>;
fn new_transform(&self, service: S) -> Self::Future {
ok(FakeAuthMiddleware {
service: Rc::new(RefCell::new(service)),
})
}
}
pub struct FakeAuthMiddleware<S> {
service: Rc<RefCell<S>>,
}
impl<S, B> Service for FakeAuthMiddleware<S>
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
S::Future: 'static,
B: 'static,
{
type Request = ServiceRequest;
type Response = ServiceResponse<B>;
type Error = Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;
fn poll_ready(&mut self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
self.service.poll_ready(cx)
}
fn call(&mut self, req: ServiceRequest) -> Self::Future {
let mut svc = self.service.clone();
Box::pin(async move {
let vals = CasbinVals {
subject: String::from("alice"),
domain: None,
};
req.extensions_mut().insert(vals);
svc.call(req).await
})
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
然后看下面的例子:
use actix_casbin_auth::casbin::function_map::key_match2;
use actix_casbin_auth::casbin::{CoreApi, DefaultModel, FileAdapter, Result};
use actix_casbin_auth::CasbinService;
use actix_web::{web, App, HttpResponse, HttpServer};
#[allow(dead_code)]
mod fake_auth;
#[actix_rt::main]
async fn main() -> Result<()> {
let m = DefaultModel::from_file("examples/rbac_with_pattern_model.conf").await?;
let a = FileAdapter::new("examples/rbac_with_pattern_policy.csv"); //You can also use diesel-adapter or sqlx-adapter
let casbin_middleware = CasbinService::new(m, a).await;
casbin_middleware
.write()
.await
.add_matching_fn(key_match2)?;
HttpServer::new(move || {
App::new()
.wrap(casbin_middleware.clone())
.wrap(FakeAuth)
.route("/pen/1", web::get().to(|| HttpResponse::Ok()))
.route("/book/{id}", web::get().to(|| HttpResponse::Ok()))
})
.bind("127.0.0.1:8080")?
.run()
.await?;
Ok(())
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
--
社区学习交流平台订阅:
- Rustcc论坛: 支持rss
- 微信公众号:Rust语言中文社区
边栏推荐
- 5-minute NLP: summary of time chronology from bag of words to transformer
- Tryout title code
- 记JPA使用自定义VO接收 JPQL查询结果
- Triode driven brushless motor
- YYGH-BUG-03
- 报错--解决core-js/modules/es.error.cause.js报错
- 手把手教你用Ucos
- Yolact++ pytoch environment
- 2 startup, interrupt and system call
- 4. use MySQL shell to install and deploy Mgr clusters | explain Mgr in simple terms
猜你喜欢

FPGA - 7 Series FPGA selectio -07- iserdese2 of advanced logic resources

D3D11_ Chili_ Tutorial (3): design a bindable/drawable system

YYGH-BUG-02
![[digital statistics DP] counting problem](/img/8d/ac05c1a88543b76fca86cd744e9cb1.jpg)
[digital statistics DP] counting problem

JDBC学习(一)——实现简单的CRUD操作

Introduction to browser tools: think sky browser, team work browser

图片按日期批量导入WPS表格

AutoCAD C# 多段線小銳角檢測
![[interval DP] stone consolidation](/img/d2/493badf59b63498782ada81be9aa43.jpg)
[interval DP] stone consolidation

Alert pop-up processing in Web Automation
随机推荐
UPC -- expression evaluation
微信小程序编译页面空白bug的原因
Freeswitch使用originate转dialplan
链表(一)——移除链表元素
Working principle of es9023 audio decoding chip
Apple MDM bypass jailfree bypass MDM configuration lock free
D3D11_ Chili_ Tutorial (3): design a bindable/drawable system
Differences between overloads, rewrites, abstract classes and interfaces
调接口事件API常用事件方法
@RequestParam
AutoCAD C# 多段線小銳角檢測
Configure multiple database connections using the SSM framework
Linked list (II) - Design linked list
ROS rviz_satellite功能包可视化GNSS轨迹,卫星地图的使用
4~20mA输入/0~5V输出的I/V转换电路
How the third-party libraries in cocoapod reference local header files
Students who do not understand the code can also send their own token. The current universal dividend model can be divided into BSC and any generation B
阿里云短信服务(完整指南),短信发送功能实现。
Introduction to openscap
JS of learning notes -- split(), replace(), join()