Introduce an environment variable to disable HTTPS, and use it when fetching WebFinger resources
You can now use USE_HTTPS=0 when debugging the federation locally.
This commit is contained in:
@@ -15,7 +15,7 @@ serde = "*"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
url = "1.7"
|
||||
webfinger = "0.1"
|
||||
webfinger = "0.2"
|
||||
|
||||
[dependencies.chrono]
|
||||
features = ["serde"]
|
||||
|
||||
@@ -16,7 +16,7 @@ use openssl::{
|
||||
};
|
||||
use webfinger::*;
|
||||
|
||||
use BASE_URL;
|
||||
use {BASE_URL, USE_HTTPS};
|
||||
use plume_common::activity_pub::{
|
||||
ApSignature, ActivityStream, Id, IntoId, PublicKey,
|
||||
inbox::WithInbox,
|
||||
@@ -97,7 +97,7 @@ impl Blog {
|
||||
}
|
||||
|
||||
fn fetch_from_webfinger(conn: &PgConnection, acct: String) -> Option<Blog> {
|
||||
match resolve(acct.clone()) {
|
||||
match resolve(acct.clone(), *USE_HTTPS) {
|
||||
Ok(wf) => wf.links.into_iter().find(|l| l.mime_type == Some(String::from("application/activity+json"))).and_then(|l| Blog::fetch_from_url(conn, l.href)),
|
||||
Err(details) => {
|
||||
println!("{:?}", details);
|
||||
|
||||
@@ -88,6 +88,8 @@ lazy_static! {
|
||||
|
||||
pub static ref DB_URL: String = env::var("DB_URL")
|
||||
.unwrap_or(format!("postgres://plume:plume@localhost/{}", env::var("DB_NAME").unwrap_or(String::from("plume"))));
|
||||
|
||||
pub static ref USE_HTTPS: bool = env::var("USE_HTTPS").map(|val| val == "1").unwrap_or(true);
|
||||
}
|
||||
|
||||
pub mod blog_authors;
|
||||
|
||||
@@ -30,7 +30,7 @@ use serde_json;
|
||||
use url::Url;
|
||||
use webfinger::*;
|
||||
|
||||
use BASE_URL;
|
||||
use {BASE_URL, USE_HTTPS};
|
||||
use db_conn::DbConn;
|
||||
use blogs::Blog;
|
||||
use blog_authors::BlogAuthor;
|
||||
@@ -143,7 +143,7 @@ impl User {
|
||||
}
|
||||
|
||||
fn fetch_from_webfinger(conn: &PgConnection, acct: String) -> Option<User> {
|
||||
match resolve(acct.clone()) {
|
||||
match resolve(acct.clone(), *USE_HTTPS) {
|
||||
Ok(wf) => wf.links.into_iter().find(|l| l.mime_type == Some(String::from("application/activity+json"))).and_then(|l| User::fetch_from_url(conn, l.href)),
|
||||
Err(details) => {
|
||||
println!("{:?}", details);
|
||||
@@ -165,7 +165,10 @@ impl User {
|
||||
json.custom_props = ap_sign; // without this workaround, publicKey is not correctly deserialized
|
||||
Some(User::from_activity(conn, json, Url::parse(url.as_ref()).unwrap().host_str().unwrap().to_string()))
|
||||
},
|
||||
Err(_) => None
|
||||
Err(e) => {
|
||||
println!("{:?}", e);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user