Compare commits

...

7 commits
v0.4.0 ... main

Author SHA1 Message Date
asonix 171e35d656 Check without default features in drone for all targets
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2023-08-17 17:01:29 -05:00
asonix e624f88536 Check without default features in drone
All checks were successful
continuous-integration/drone/push Build is passing
2023-08-17 16:59:07 -05:00
asonix 0835c0118e Make awc optional
All checks were successful
continuous-integration/drone/push Build is passing
2023-08-17 16:57:49 -05:00
asonix 5dec9f6427 Update flake 2023-08-17 16:57:39 -05:00
asonix c4d97f378f Update pretty env logger
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-03 13:12:28 -05:00
asonix 2f5cdc93f7 Add nix 2023-06-03 13:09:59 -05:00
Aode (Lion) 8ab8f74821 Update versions and examples
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-03-08 11:56:05 -06:00
7 changed files with 151 additions and 27 deletions

View file

@ -23,6 +23,7 @@ steps:
commands: commands:
- rustup component add clippy - rustup component add clippy
- cargo clippy -- -D warnings - cargo clippy -- -D warnings
- cargo clippy --no-default-features -- -D warnings
- cargo clippy --example fetch -- -D warnings - cargo clippy --example fetch -- -D warnings
- cargo clippy --example resolver -- -D warnings - cargo clippy --example resolver -- -D warnings
@ -91,6 +92,7 @@ steps:
pull: always pull: always
commands: commands:
- cargo check --target=$TARGET - cargo check --target=$TARGET
- cargo check --target=$TARGET --no-default-features
- cargo check --target=$TARGET --example fetch - cargo check --target=$TARGET --example fetch
- cargo check --target=$TARGET --example resolver - cargo check --target=$TARGET --example resolver
@ -125,6 +127,7 @@ steps:
pull: always pull: always
commands: commands:
- cargo check --target=$TARGET - cargo check --target=$TARGET
- cargo check --target=$TARGET --no-default-features
- cargo check --target=$TARGET --example fetch - cargo check --target=$TARGET --example fetch
- cargo check --target=$TARGET --example resolver - cargo check --target=$TARGET --example resolver
@ -159,6 +162,7 @@ steps:
pull: always pull: always
commands: commands:
- cargo check --target=$TARGET - cargo check --target=$TARGET
- cargo check --target=$TARGET --no-default-features
- cargo check --target=$TARGET --example fetch - cargo check --target=$TARGET --example fetch
- cargo check --target=$TARGET --example resolver - cargo check --target=$TARGET --example resolver

4
.gitignore vendored
View file

@ -1,3 +1,5 @@
/target /target
**/*.rs.bk **/*.rs.bk
Cargo.lock Cargo.lock
.direnv
.envrc

View file

@ -1,21 +1,25 @@
[package] [package]
name = "actix-webfinger" name = "actix-webfinger"
description = "Types and helpers to create and fetch Webfinger resources" description = "Types and helpers to create and fetch Webfinger resources"
version = "0.4.0" version = "0.5.0"
license = "GPL-3.0" license = "GPL-3.0"
authors = ["asonix <asonix@asonix.dog>"] authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.dog/asonix/actix-webfinger" repository = "https://git.asonix.dog/asonix/actix-webfinger"
readme = "README.md" readme = "README.md"
edition = "2021" edition = "2021"
[features]
default = ["client"]
client = ["dep:awc"]
[dependencies] [dependencies]
actix-rt = "2.6.0" actix-rt = "2.6.0"
actix-web = { version = "4.0.1", default-features = false } actix-web = { version = "4.0.1", default-features = false }
awc = { version = "3.0.0", default-features = false } awc = { version = "3.0.0", default-features = false, optional = true }
serde = "1.0" serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"
thiserror = "1.0" thiserror = "1.0"
[dev-dependencies] [dev-dependencies]
pretty_env_logger = "0.4" pretty_env_logger = "0.5"
serde_json = "1.0" serde_json = "1.0"

View file

@ -13,23 +13,30 @@ First, add Actix Webfinger as a dependency
```toml ```toml
[dependencies] [dependencies]
actix-rt = "=2.0.0-beta.1" actix-rt = "2.6.0"
actix-web = "4.0.0-alpha.1" actix-web = "4.0.0"
actix-webfinger = "0.4.0-beta.1" actix-webfinger = "0.4.0"
``` ```
Then use it in your application Then use it in your application
#### Client Example #### Client Example
```rust ```rust
use actix_web::client::Client;
use actix_webfinger::Webfinger; use actix_webfinger::Webfinger;
use awc::Client;
use std::error::Error; use std::error::Error;
#[actix_rt::main] #[actix_rt::main]
async fn main() -> Result<(), Box<dyn Error>> { async fn main() -> Result<(), Box<dyn Error>> {
let client = Client::default(); let client = Client::default();
let wf = Webfinger::fetch(&client, "asonix@asonix.dog", "localhost:8000", false).await?; let wf = Webfinger::fetch(
&client,
Some("acct:"),
"asonix@localhost:8000",
"localhost:8000",
false,
)
.await?;
println!("asonix's webfinger:\n{:#?}", wf); println!("asonix's webfinger:\n{:#?}", wf);
Ok(()) Ok(())
@ -38,7 +45,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
#### Server Example #### Server Example
```rust ```rust
use actix_web::{web::Data, App, HttpServer}; use actix_web::{middleware::Logger, web::Data, App, HttpServer};
use actix_webfinger::{Resolver, Webfinger}; use actix_webfinger::{Resolver, Webfinger};
use std::{error::Error, future::Future, pin::Pin}; use std::{error::Error, future::Future, pin::Pin};
@ -49,16 +56,19 @@ pub struct MyState {
pub struct MyResolver; pub struct MyResolver;
type LocalBoxFuture<'a, Output> = Pin<Box<dyn Future<Output = Output> + 'a>>;
impl Resolver for MyResolver { impl Resolver for MyResolver {
type State = Data<MyState>; type State = Data<MyState>;
type Error = actix_web::error::JsonPayloadError; type Error = actix_web::error::JsonPayloadError;
fn find( fn find(
scheme: Option<&str>,
account: &str, account: &str,
domain: &str, domain: &str,
state: Data<MyState>, state: Data<MyState>,
) -> Pin<Box<dyn Future<Output = Result<Option<Webfinger>, Self::Error>>>> { ) -> LocalBoxFuture<'static, Result<Option<Webfinger>, Self::Error>> {
let w = if domain == state.domain { let w = if scheme == Some("acct:") && domain == state.domain {
Some(Webfinger::new(&format!("{}@{}", account, domain))) Some(Webfinger::new(&format!("{}@{}", account, domain)))
} else { } else {
None None
@ -70,12 +80,15 @@ impl Resolver for MyResolver {
#[actix_rt::main] #[actix_rt::main]
async fn main() -> Result<(), Box<dyn Error>> { async fn main() -> Result<(), Box<dyn Error>> {
std::env::set_var("RUST_LOG", "info");
pretty_env_logger::init();
HttpServer::new(|| { HttpServer::new(|| {
App::new() App::new()
.data(MyState { .app_data(Data::new(MyState {
domain: "asonix.dog".to_owned(), domain: "localhost:8000".to_owned(),
}) }))
.service(actix_webfinger::resource::<_, MyResolver>()) .wrap(Logger::default())
.service(actix_webfinger::resource::<MyResolver>())
}) })
.bind("127.0.0.1:8000")? .bind("127.0.0.1:8000")?
.run() .run()

61
flake.lock Normal file
View file

@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1689068808,
"narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1692174805,
"narHash": "sha256-xmNPFDi/AUMIxwgOH/IVom55Dks34u1g7sFKKebxUm0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "caac0eb6bdcad0b32cb2522e03e4002c8975c62e",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

25
flake.nix Normal file
View file

@ -0,0 +1,25 @@
{
description = "actix-webfinger";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
in
{
packages.default = pkgs.hello;
devShell = with pkgs; mkShell {
nativeBuildInputs = [ cargo cargo-outdated cargo-zigbuild clippy gcc protobuf rust-analyzer rustc rustfmt ];
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};
});
}

View file

@ -13,9 +13,9 @@
//! //!
//! ```toml //! ```toml
//! [dependencies] //! [dependencies]
//! actix = "0.10.0-alpha.1" //! actix-rt = "2.6.0"
//! actix-web = "3.0.0-alpha.1" //! actix-web = "4.0.0"
//! actix-webfinger = "0.3.0-alpha.2" //! actix-webfinger = "0.4.0"
//! ``` //! ```
//! //!
//! Then use it in your application //! Then use it in your application
@ -29,7 +29,14 @@
//! #[actix_rt::main] //! #[actix_rt::main]
//! async fn main() -> Result<(), Box<dyn Error>> { //! async fn main() -> Result<(), Box<dyn Error>> {
//! let client = Client::default(); //! let client = Client::default();
//! let wf = Webfinger::fetch(&client, None, "asonix@asonix.dog", "localhost:8000", false).await?; //! let wf = Webfinger::fetch(
//! &client,
//! Some("acct:"),
//! "asonix@localhost:8000",
//! "localhost:8000",
//! false,
//! )
//! .await?;
//! //!
//! println!("asonix's webfinger:\n{:#?}", wf); //! println!("asonix's webfinger:\n{:#?}", wf);
//! Ok(()) //! Ok(())
@ -38,7 +45,7 @@
//! //!
//! #### Server Example //! #### Server Example
//! ```rust,ignore //! ```rust,ignore
//! use actix_web::{web::Data, App, HttpServer}; //! use actix_web::{middleware::Logger, web::Data, App, HttpServer};
//! use actix_webfinger::{Resolver, Webfinger}; //! use actix_webfinger::{Resolver, Webfinger};
//! use std::{error::Error, future::Future, pin::Pin}; //! use std::{error::Error, future::Future, pin::Pin};
//! //!
@ -49,16 +56,19 @@
//! //!
//! pub struct MyResolver; //! pub struct MyResolver;
//! //!
//! type LocalBoxFuture<'a, Output> = Pin<Box<dyn Future<Output = Output> + 'a>>;
//!
//! impl Resolver for MyResolver { //! impl Resolver for MyResolver {
//! type State = Data<MyState>; //! type State = Data<MyState>;
//! type Error = actix_web::error::JsonPayloadError; //! type Error = actix_web::error::JsonPayloadError;
//! //!
//! fn find( //! fn find(
//! scheme: Option<&str>,
//! account: &str, //! account: &str,
//! domain: &str, //! domain: &str,
//! state: S, //! state: Data<MyState>,
//! ) -> Pin<Box<dyn Future<Output = Result<Option<Webfinger>, Self::Error>>>> { //! ) -> LocalBoxFuture<'static, Result<Option<Webfinger>, Self::Error>> {
//! let w = if domain == state.domain { //! let w = if scheme == Some("acct:") && domain == state.domain {
//! Some(Webfinger::new(&format!("{}@{}", account, domain))) //! Some(Webfinger::new(&format!("{}@{}", account, domain)))
//! } else { //! } else {
//! None //! None
@ -70,11 +80,14 @@
//! //!
//! #[actix_rt::main] //! #[actix_rt::main]
//! async fn main() -> Result<(), Box<dyn Error>> { //! async fn main() -> Result<(), Box<dyn Error>> {
//! std::env::set_var("RUST_LOG", "info");
//! pretty_env_logger::init();
//! HttpServer::new(|| { //! HttpServer::new(|| {
//! App::new() //! App::new()
//! .data(MyState { //! .app_data(Data::new(MyState {
//! domain: "asonix.dog".to_owned(), //! domain: "localhost:8000".to_owned(),
//! }) //! }))
//! .wrap(Logger::default())
//! .service(actix_webfinger::resource::<MyResolver>()) //! .service(actix_webfinger::resource::<MyResolver>())
//! }) //! })
//! .bind("127.0.0.1:8000")? //! .bind("127.0.0.1:8000")?
@ -104,6 +117,7 @@ use actix_web::{
web::{get, Query}, web::{get, Query},
FromRequest, HttpResponse, Resource, FromRequest, HttpResponse, Resource,
}; };
#[cfg(feature = "client")]
use awc::Client; use awc::Client;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
@ -622,6 +636,7 @@ impl Webfinger {
.json(&self) .json(&self)
} }
#[cfg(feature = "client")]
/// Fetch a webfinger with subject `user` from a given `domain` /// Fetch a webfinger with subject `user` from a given `domain`
/// ///
/// This method takes a `Client` so derivative works can provide their own configured clients /// This method takes a `Client` so derivative works can provide their own configured clients