mirror of
https://github.com/tribufu/sdk-rust
synced 2025-06-19 12:34:19 +00:00
Create initial api wrapper (#2)
* Api v0.1? * Split crates * Update api
This commit is contained in:
20
src/actix/Cargo.toml
Normal file
20
src/actix/Cargo.toml
Normal file
@ -0,0 +1,20 @@
|
||||
[package]
|
||||
name = "tribufu-actix"
|
||||
version = "0.0.4"
|
||||
description = "Tribufu Actix Extension"
|
||||
repository = "https://github.com/Tribufu/TribufuRust"
|
||||
authors = ["Tribufu <contact@tribufu.com>"]
|
||||
license = "Apache-2.0"
|
||||
readme = "README.md"
|
||||
edition = "2021"
|
||||
publish = true
|
||||
|
||||
[lib]
|
||||
name = "tribufu_actix"
|
||||
crate-type = ["rlib"]
|
||||
path = "lib.rs"
|
||||
|
||||
[dependencies]
|
||||
actix-web = { version = "4", features = ["rustls"] }
|
||||
mintaka-error = { version = "0.0.1" }
|
||||
tribufu-api = { path = "../api" }
|
24
src/actix/lib.rs
Normal file
24
src/actix/lib.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
|
||||
use actix_web::HttpRequest;
|
||||
use tribufu_api::TribufuApi;
|
||||
|
||||
pub trait TribufuApiActixExtension {
|
||||
fn from_actix(req: &HttpRequest) -> Self;
|
||||
}
|
||||
|
||||
impl TribufuApiActixExtension for TribufuApi {
|
||||
fn from_actix(req: &HttpRequest) -> Self {
|
||||
let mut api = Self::with_client_from_env().unwrap_or_default();
|
||||
|
||||
if let Some(authorization) = req.headers().get("Authorization") {
|
||||
let authorization = authorization.to_str().unwrap();
|
||||
|
||||
if authorization.starts_with("Bearer ") {
|
||||
api = Self::with_user(authorization[7..].to_string());
|
||||
}
|
||||
}
|
||||
|
||||
return api;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user