Compare commits

..

3 commits

10 changed files with 147 additions and 11 deletions

View file

@ -9,6 +9,7 @@
<sourceFolder url="file://$MODULE_DIR$/acrate-inbox/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/acrate-nodeinfo/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/acrate-nodeinfo/tests" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/acrate-webfinger/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />

12
.idea/dataSources.xml Normal file
View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="acrate" uuid="8258414e-095d-430b-a0a5-b48e72af23a9">
<driver-ref>postgresql</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
<jdbc-url>jdbc:postgresql:///acrate</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

6
.idea/sqldialects.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/acrate-core/migrations/2024-11-14-031744_Add webfinger table/up.sql" dialect="GenericSQL" />
</component>
</project>

View file

@ -0,0 +1,8 @@
DROP FUNCTION get_meta_property;
DROP FUNCTION get_meta_link;
DROP FUNCTION get_meta_aliases;
DROP TABLE meta_property;
DROP TABLE meta_link_property;
DROP TABLE meta_link;
DROP TABLE meta_alias;

View file

@ -0,0 +1,47 @@
CREATE TABLE meta_alias (
id UUID DEFAULT gen_random_uuid(),
pattern BPCHAR NOT NULL,
alias BPCHAR NOT NULL,
CONSTRAINT unique_aliases UNIQUE (alias),
PRIMARY KEY (id)
);
CREATE TABLE meta_link (
id UUID DEFAULT gen_random_uuid(),
pattern BPCHAR NOT NULL,
rel BPCHAR NOT NULL,
type BPCHAR,
href BPCHAR,
PRIMARY KEY (id)
);
CREATE TABLE meta_link_property (
id UUID DEFAULT gen_random_uuid(),
link UUID REFERENCES meta_link (id),
rel BPCHAR NOT NULL,
value BPCHAR,
PRIMARY KEY (id)
);
CREATE TABLE meta_property (
id UUID DEFAULT gen_random_uuid(),
pattern BPCHAR NOT NULL,
value BPCHAR,
PRIMARY KEY (id)
);
CREATE FUNCTION get_meta_aliases(BPCHAR) RETURNS SETOF meta_alias AS $$
SELECT * FROM meta_alias WHERE meta_alias.pattern ILIKE $1;
$$ LANGUAGE SQL;
CREATE FUNCTION get_meta_link(BPCHAR) RETURNS SETOF meta_link AS $$
SELECT * FROM meta_link WHERE meta_link.pattern ILIKE $1;
$$ LANGUAGE SQL;
CREATE FUNCTION get_meta_property(BPCHAR) RETURNS SETOF meta_property AS $$
SELECT * FROM meta_property WHERE meta_property.pattern ILIKE $1;
$$ LANGUAGE SQL;

46
acrate-core/src/schema.rs Normal file
View file

@ -0,0 +1,46 @@
// @generated automatically by Diesel CLI.
diesel::table! {
meta_alias (id) {
id -> Uuid,
pattern -> Bpchar,
alias -> Bpchar,
}
}
diesel::table! {
meta_link (id) {
id -> Uuid,
pattern -> Bpchar,
rel -> Bpchar,
#[sql_name = "type"]
type_ -> Nullable<Bpchar>,
href -> Nullable<Bpchar>,
}
}
diesel::table! {
meta_link_property (id) {
id -> Uuid,
link -> Nullable<Uuid>,
rel -> Bpchar,
value -> Nullable<Bpchar>,
}
}
diesel::table! {
meta_property (id) {
id -> Uuid,
pattern -> Bpchar,
value -> Nullable<Bpchar>,
}
}
diesel::joinable!(meta_link_property -> meta_link (link));
diesel::allow_tables_to_appear_in_same_query!(
meta_alias,
meta_link,
meta_link_property,
meta_property,
);

View file

@ -5,8 +5,10 @@ edition = "2021"
[dependencies]
anyhow = "1.0.93"
axum = "0.7.7"
axum = { version = "0.7.7", features = ["macros"] }
axum-extra = { version = "0.9.4", features = ["query"] }
log = "0.4.22"
micronfig = "0.3.0"
pretty_env_logger = "0.5.0"
serde = { version = "1.0.215", features = ["derive"] }
tokio = { version = "1.41.1", features = ["macros", "net", "rt-multi-thread"] }

View file

@ -1,3 +1,3 @@
micronfig::config!(
ACRATE_INBOX_BIND_ADDRESS: String,
ACRATE_WEBFINGER_BIND_ADDRESS: String,
);

View file

@ -11,11 +11,11 @@ async fn main() -> anyhow::Result<std::convert::Infallible> {
log::trace!("Creating Axum router...");
let app = axum::Router::new()
.route("/inbox", axum::routing::post(route::inbox_handler));
.route("/.well-known/webfinger", axum::routing::get(route::webfinger_handler));
log::trace!("Axum router created successfully!");
log::trace!("Creating Tokio listener...");
let bind_address = config::ACRATE_INBOX_BIND_ADDRESS();
let bind_address = config::ACRATE_WEBFINGER_BIND_ADDRESS();
let listener = tokio::net::TcpListener::bind(bind_address)
.await
.context("failed to bind listener to address")?;

View file

@ -1,8 +1,22 @@
#[allow(unreachable_code)]
pub async fn inbox_handler() {
todo!("pre-validation hook");
todo!("validate signature");
todo!("post-validation hook");
todo!("database storage");
todo!("post-storage hook");
use axum::http::StatusCode;
use axum_extra::extract::Query;
use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct WebfingerQuery {
pub resource: String,
#[serde(default)]
pub rel: Vec<String>,
}
#[axum::debug_handler]
pub async fn webfinger_handler(
Query(WebfingerQuery {resource, rel}): Query<WebfingerQuery>
) -> StatusCode {
log::info!("Handling a WebFinger request!");
log::debug!("Resource is: {resource:#?}");
log::debug!("Rel is: {rel:#?}");
StatusCode::NO_CONTENT
}