当前位置:网站首页>[rust daily] May 24, 2020 rush, rocket, Mun, caspin
[rust daily] May 24, 2020 rush, rocket, Mun, caspin
2022-06-28 06:40:00 【51CTO】
Rash v0.1.0 released!
Rash v0.1.0 released!
https://github.com/pando85/rash
Rash It's a kind of reception Ansible Tool inspired Declarative Shell Scripting language .
- Avoid lengthy and unmanageable Shell Script
- similar Ansible Such a programming style
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 Now you can go through stable Rust 1.45 Compile the .
Rocket can be compiled on stable Rust 1.45
https://github.com/SergioBenitez/Rocket/issues/19#issuecomment-630650328
Rocket Now you can go through stable Rust 1.45 Compile the .
Mun v0.2.0 Released
Mun v0.2.0 Released
https://github.com/mun-lang/mun/releases/tag/v0.2.0
Mun It's a pass iteration An embedded programming language that can continuously create iterations .Mun The idea of language comes from finding a way to avoid Lua The disadvantages of dynamic scripting language can be found in Rust In language hot-reload( Thermal loading ) New programming language . therefore ,Mun First of all, a new language cannot be Rust Language competitors , At the same time, you can Rust Language ( or C/C++) Host language Seamlessly embed programming in .Mun Completely by Rust language , The main software package is rust-analyzer and rustc . The main features include :
- Ahead of time compilation
- Statically typed
- First class hot-reloading
New version updated features :
- 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 middleware
Actix Casbin Middleware
https://github.com/casbin-rs/actix-casbin-auth
Casbin yes Rust Language web page architecture actix-web framework Access control middleware .
install (install)
stay Cargo.toml Add the following :
demand (requirement)
Casbin Only responsible for permission management , So we need to achieve Authentication Middleware To confirm the user . Therefore, it is necessary to put the subject(username) and domain(optional) The information of actix_casbin_auth::CasbinVals Add to Extension in .
Take the following example :
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.
Then look at the following example :
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.
--
Community learning exchange platform subscription :
- Rustcc Forum : Support rss
- WeChat official account :Rust Language Chinese community
边栏推荐
- KMP string
- Unity packaging webgl uses IIS to solve the error
- Promotion intégrale et ordre des octets de fin de taille
- FPGA - 7 Series FPGA selectio -09- io of advanced logic resources_ FIFO
- 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
- 饿久了,大脑会进入“省电模式”!感官被削弱,还看不清东西丨爱丁堡大学...
- 普歌 -- getOrDefault()方法理解
- Differences between basic types and packaging classes
- freeswitch设置最大呼叫时长
- AutoCAD C # Polyline Small Sharp angle Detection
猜你喜欢

搭建你jmeter+jenkins+ant

饿久了,大脑会进入“省电模式”!感官被削弱,还看不清东西丨爱丁堡大学...

pytorch RNN 学习笔记

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

Error reporting - resolve core JS / modules / es error. cause. JS error
![[staff] arpeggio mark](/img/45/0ee0089b947b467344b247839893d7.jpg)
[staff] arpeggio mark

death_ satan/hyperf-validate

js正则表达式系统讲解(全面的总结)

Linux MySQL implements root user login without password

链表(三)——反转链表
随机推荐
推荐10个好用到爆的Jupyter Notebook插件,让你效率飞起
FPGA - 7 Series FPGA selectio -09- io of advanced logic resources_ FIFO
Cmake tips
Install redis on windows and permanently change the password, and integrate redis with the SSM framework
【Rust翻译】从头实现Rust异步执行器
AutoCAD C polyline self intersection detection
MySQL (I) - Installation
Use the SQL SELECT count distinct query statement to count the total number of unique values of a field in the database
图片按日期批量导入WPS表格
Puge -- three basic sorting, bubbling, selection and quickness
[interval DP] stone consolidation
Deleting MySQL under Linux
@RequestParam
freeswitch设置最大呼叫时长
4. use MySQL shell to install and deploy Mgr clusters | explain Mgr in simple terms
FPM tool installation
声网 VQA:将实时互动中未知的视频画质用户主观体验变可知
[digital statistics DP] counting problem
RN7302三相电量检测(基于STM32单片机)
Servlet value passing JSP