Update to activitypub with extensions

This commit is contained in:
asonix 2020-03-18 17:49:56 -05:00
parent f48d404a15
commit 2b36909d2f
5 changed files with 30 additions and 48 deletions

22
Cargo.lock generated
View file

@ -2,9 +2,8 @@
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]] [[package]]
name = "activitystreams" name = "activitystreams"
version = "0.5.0-alpha.8" version = "0.5.0-alpha.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://git.asonix.dog/Aardwolf/activitystreams?branch=asonix/try-extensions#3258d7e0a7032d9959ad5d2ee05206be8e5a91af"
checksum = "78489a7b8d92f8c23f3dc1b69da158c0a4ca02edf0f4007955fafbca667275dd"
dependencies = [ dependencies = [
"activitystreams-derive", "activitystreams-derive",
"chrono", "chrono",
@ -17,9 +16,8 @@ dependencies = [
[[package]] [[package]]
name = "activitystreams-derive" name = "activitystreams-derive"
version = "0.5.0-alpha.3" version = "0.5.0-alpha.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://git.asonix.dog/Aardwolf/activitystreams?branch=asonix/try-extensions#3258d7e0a7032d9959ad5d2ee05206be8e5a91af"
checksum = "f95c948a832a0b7b230b28369bafe79477bb8ebe7306dc97bcaff43832d3cc4d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -403,9 +401,9 @@ dependencies = [
[[package]] [[package]]
name = "arc-swap" name = "arc-swap"
version = "0.4.4" version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff" checksum = "d663a8e9a99154b5fb793032533f6328da35e23aac63d5c152279aa8ba356825"
[[package]] [[package]]
name = "async-trait" name = "async-trait"
@ -1800,18 +1798,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.104" version = "1.0.105"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" checksum = "e707fbbf255b8fc8c3b99abb91e7257a622caeb20a9818cbadbeeede4e0932ff"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.104" version = "1.0.105"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" checksum = "ac5d00fc561ba2724df6758a17de23df5914f20e41cb00f94d5b7ae42fffaff8"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View file

@ -12,7 +12,7 @@ actix = "0.10.0-alpha.2"
actix-rt = "1.0.0" actix-rt = "1.0.0"
actix-web = { version = "3.0.0-alpha.1", features = ["rustls"] } actix-web = { version = "3.0.0-alpha.1", features = ["rustls"] }
actix-webfinger = { version = "0.3.0-alpha.3" } actix-webfinger = { version = "0.3.0-alpha.3" }
activitystreams = "0.5.0-alpha.8" activitystreams = { version = "0.5.0-alpha.9", git = "https://git.asonix.dog/Aardwolf/activitystreams", branch = "asonix/try-extensions" }
base64 = "0.12" base64 = "0.12"
bb8-postgres = "0.4.0" bb8-postgres = "0.4.0"
dotenv = "0.15.0" dotenv = "0.15.0"

View file

@ -1,7 +1,9 @@
use activitystreams::{ use activitystreams::{
actor::Actor,
ext::Extension,
object::{Object, ObjectBox}, object::{Object, ObjectBox},
primitives::XsdAnyUri, primitives::XsdAnyUri,
PropRefs, Base, BaseBox, PropRefs,
}; };
use std::collections::HashMap; use std::collections::HashMap;
@ -13,16 +15,9 @@ pub struct PublicKey {
pub public_key_pem: String, pub public_key_pem: String,
} }
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] impl<T> Extension<T> for PublicKey where T: Actor {}
#[serde(rename_all = "camelCase")]
pub struct PublicKeyExtension<T> {
public_key: PublicKey,
#[serde(flatten)] #[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, PropRefs)]
extending: T,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PropRefs)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
#[prop_refs(Object)] #[prop_refs(Object)]
pub struct AnyExistingObject { pub struct AnyExistingObject {
@ -91,15 +86,6 @@ pub struct Endpoints {
shared_inbox: Option<XsdAnyUri>, shared_inbox: Option<XsdAnyUri>,
} }
impl PublicKey {
pub fn extend<T>(self, extending: T) -> PublicKeyExtension<T> {
PublicKeyExtension {
public_key: self,
extending,
}
}
}
impl ValidObjects { impl ValidObjects {
pub fn id(&self) -> &XsdAnyUri { pub fn id(&self) -> &XsdAnyUri {
match self { match self {

View file

@ -7,10 +7,11 @@ use crate::{
state::{State, UrlKind}, state::{State, UrlKind},
}; };
use activitystreams::{ use activitystreams::{
activity::apub::{Accept, Announce, Follow, Undo}, activity::{Accept, Announce, Follow, Undo},
context, context,
object::properties::ObjectProperties, object::properties::ObjectProperties,
primitives::XsdAnyUri, primitives::XsdAnyUri,
public, security,
}; };
use actix_web::{web, HttpResponse}; use actix_web::{web, HttpResponse};
use futures::join; use futures::join;
@ -18,12 +19,6 @@ use http_signature_normalization_actix::middleware::SignatureVerified;
use log::error; use log::error;
use std::convert::TryInto; use std::convert::TryInto;
fn public() -> XsdAnyUri {
"https://www.w3.org/ns/activitystreams#Public"
.parse()
.unwrap()
}
pub async fn inbox( pub async fn inbox(
db: web::Data<Db>, db: web::Data<Db>,
state: web::Data<State>, state: web::Data<State>,
@ -203,7 +198,7 @@ fn generate_undo_follow(
undo.undo_props undo.undo_props
.set_actor_xsd_any_uri(my_id.clone())? .set_actor_xsd_any_uri(my_id.clone())?
.set_object_object_box({ .set_object_base_box({
let mut follow = Follow::default(); let mut follow = Follow::default();
follow follow
@ -272,7 +267,7 @@ fn generate_accept_follow(
accept accept
.accept_props .accept_props
.set_actor_xsd_any_uri(my_id.clone())? .set_actor_xsd_any_uri(my_id.clone())?
.set_object_object_box({ .set_object_base_box({
let mut follow = Follow::default(); let mut follow = Follow::default();
follow.object_props.set_id(input_id.clone())?; follow.object_props.set_id(input_id.clone())?;
@ -303,7 +298,7 @@ where
t.as_mut() t.as_mut()
.set_id(id.try_into()?)? .set_id(id.try_into()?)?
.set_many_to_xsd_any_uris(vec![to.try_into()?])? .set_many_to_xsd_any_uris(vec![to.try_into()?])?
.set_context_xsd_any_uri(context())?; .set_many_context_xsd_any_uris(vec![context(), security()])?;
Ok(t) Ok(t)
} }

View file

@ -1,4 +1,7 @@
use activitystreams::{actor::apub::Application, context, endpoint::EndpointProperties}; use activitystreams::{
actor::Application, context, endpoint::EndpointProperties, ext::Extensible,
object::properties::ObjectProperties,
};
use actix_web::{middleware::Logger, web, App, HttpResponse, HttpServer, Responder}; use actix_web::{middleware::Logger, web, App, HttpResponse, HttpServer, Responder};
use bb8_postgres::tokio_postgres; use bb8_postgres::tokio_postgres;
use http_signature_normalization_actix::prelude::{VerifyDigest, VerifySignature}; use http_signature_normalization_actix::prelude::{VerifyDigest, VerifySignature};
@ -50,13 +53,13 @@ async fn index() -> impl Responder {
} }
async fn actor_route(state: web::Data<State>) -> Result<impl Responder, MyError> { async fn actor_route(state: web::Data<State>) -> Result<impl Responder, MyError> {
let mut application = Application::default(); let mut application = Application::full();
let mut endpoint = EndpointProperties::default(); let mut endpoint = EndpointProperties::default();
endpoint.set_shared_inbox(state.generate_url(UrlKind::Inbox))?; endpoint.set_shared_inbox(state.generate_url(UrlKind::Inbox))?;
application let props: &mut ObjectProperties = application.as_mut();
.object_props props
.set_id(state.generate_url(UrlKind::Actor))? .set_id(state.generate_url(UrlKind::Actor))?
.set_summary_xsd_string("AodeRelay bot")? .set_summary_xsd_string("AodeRelay bot")?
.set_name_xsd_string("AodeRelay")? .set_name_xsd_string("AodeRelay")?
@ -64,7 +67,7 @@ async fn actor_route(state: web::Data<State>) -> Result<impl Responder, MyError>
.set_context_xsd_any_uri(context())?; .set_context_xsd_any_uri(context())?;
application application
.ap_actor_props .extension
.set_preferred_username("relay")? .set_preferred_username("relay")?
.set_followers(state.generate_url(UrlKind::Followers))? .set_followers(state.generate_url(UrlKind::Followers))?
.set_following(state.generate_url(UrlKind::Following))? .set_following(state.generate_url(UrlKind::Following))?
@ -78,7 +81,7 @@ async fn actor_route(state: web::Data<State>) -> Result<impl Responder, MyError>
public_key_pem: state.settings.public_key.to_pem_pkcs8()?, public_key_pem: state.settings.public_key.to_pem_pkcs8()?,
}; };
Ok(ok(public_key.extend(application))) Ok(ok(application.extend(public_key)))
} }
#[actix_rt::main] #[actix_rt::main]