Work towards authorized fetch
This commit is contained in:
parent
f3c05dae62
commit
2b4e802914
@ -42,6 +42,7 @@ pub struct NewInstance {
|
||||
|
||||
lazy_static! {
|
||||
static ref LOCAL_INSTANCE: RwLock<Option<Instance>> = RwLock::new(None);
|
||||
static ref INSTANCE_USER: RwLock<Option<User>> = RwLock::new(None);
|
||||
}
|
||||
|
||||
impl Instance {
|
||||
@ -57,6 +58,14 @@ impl Instance {
|
||||
.ok_or(Error::NotFound)
|
||||
}
|
||||
|
||||
pub fn set_local_user(u: User) {
|
||||
INSTANCE_USER.write().unwrap().replace(u);
|
||||
}
|
||||
|
||||
pub fn get_local_user() -> Result<User> {
|
||||
INSTANCE_USER.read().unwrap().clone().ok_or(Error::NotFound)
|
||||
}
|
||||
|
||||
pub fn get_local_uncached(conn: &Connection) -> Result<Instance> {
|
||||
instances::table
|
||||
.filter(instances::local.eq(true))
|
||||
|
@ -29,7 +29,6 @@ table! {
|
||||
is_owner -> Bool,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
blogs (id) {
|
||||
id -> Int4,
|
||||
|
@ -230,11 +230,8 @@ impl User {
|
||||
}
|
||||
|
||||
fn fetch(url: &str) -> Result<CustomPerson> {
|
||||
let mut res = ClientBuilder::new()
|
||||
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||
.build()?
|
||||
.get(url)
|
||||
.header(
|
||||
let mut headers = plume_common::activity_pub::request::headers();
|
||||
headers.insert(
|
||||
ACCEPT,
|
||||
HeaderValue::from_str(
|
||||
&ap_accept_header()
|
||||
@ -242,8 +239,19 @@ impl User {
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "),
|
||||
)?,
|
||||
);
|
||||
let lu = Instance::get_local_user()?;
|
||||
let mut res = ClientBuilder::new()
|
||||
.connect_timeout(Some(std::time::Duration::from_secs(5)))
|
||||
.build()?
|
||||
.get(url)
|
||||
.headers(headers.clone())
|
||||
.header(
|
||||
"Signature",
|
||||
plume_common::activity_pub::request::signature(&lu, &headers).expect(""),
|
||||
)
|
||||
.send()?;
|
||||
|
||||
let text = &res.text()?;
|
||||
// without this workaround, publicKey is not correctly deserialized
|
||||
let ap_sign = serde_json::from_str::<ApSignature>(text)?;
|
||||
|
Loading…
Reference in New Issue
Block a user