Rash v0.1.0 released! https://github.com/pando85/rash
entrypoint.sh:set -eREQUIRED_PARAMS="VAULT_URLVAULT_ROLE_IDVAULT_SECRET_IDVAULT_SECRET_PATH"for required in $REQUIRED_PARAMS ; do[[ -z "${!required}" ]] && echo "$required IS NOT DEFINED" && exit 1doneecho "[$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 "$@"
entrypoint.rh:- name: Verify input parametersassert:that:- VAULT_URL is defined- VAULT_ROLE_ID is defined- VAULT_SECRET_ID is defined- VAULT_SECRET_PATH is defined- name: launch docker CMDcommand: {{ input.args }}transfer_ownership: yesenv:APP1_API_KEY: "{{ lookup('vault', env.VAULT_SECRET_PATH ) }}"
Rocket can be compiled on stable Rust 1.45 https://github.com/SergioBenitez/Rocket/issues/19#issuecomment-630650328
Mun v0.2.0 Released https://mun-lang.org/ https://github.com/mun-lang/mun/releases/tag/v0.2.0
Actix Casbin Middleware https://github.com/casbin-rs/actix-casbin-auth
actix-casbin-auth = "0.2.0"actix-rt = "1.1.1"actix-web = "2.0.0"
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 FakeAuthwhereS: 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>whereS: 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})}}
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-adapterlet 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(())}
原文作者:Rust语言中文社区;如有侵权,请联系管理员删除。