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

View file

@ -12,7 +12,7 @@ actix = "0.10.0-alpha.2"
actix-rt = "1.0.0"
actix-web = { version = "3.0.0-alpha.1", features = ["rustls"] }
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"
bb8-postgres = "0.4.0"
dotenv = "0.15.0"

View file

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

View file

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

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 bb8_postgres::tokio_postgres;
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> {
let mut application = Application::default();
let mut application = Application::full();
let mut endpoint = EndpointProperties::default();
endpoint.set_shared_inbox(state.generate_url(UrlKind::Inbox))?;
application
.object_props
let props: &mut ObjectProperties = application.as_mut();
props
.set_id(state.generate_url(UrlKind::Actor))?
.set_summary_xsd_string("AodeRelay bot")?
.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())?;
application
.ap_actor_props
.extension
.set_preferred_username("relay")?
.set_followers(state.generate_url(UrlKind::Followers))?
.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()?,
};
Ok(ok(public_key.extend(application)))
Ok(ok(application.extend(public_key)))
}
#[actix_rt::main]