Compare commits

..

No commits in common. "c2da1723cf2f3a967c1b4605b8d74ac4cf044068" and "b46a995c09efd68cc7f4e64468c118c3357fda80" have entirely different histories.

4 changed files with 71 additions and 84 deletions

View file

@ -6,8 +6,6 @@ edition = "2021"
[dependencies]
diesel = "2.2.4"
diesel_migrations = "2.2.0"
acrate-hostmeta = { path = "../acrate-hostmeta" }
acrate-nodeinfo = { path = "../acrate-nodeinfo" }
[lints.clippy]
tabs-in-doc-comments = "allow"

View file

@ -1,4 +1,14 @@
//! Core crate of the `acrate` project.
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
pub use acrate_nodeinfo as nodeinfo;
pub use acrate_hostmeta as hostmeta;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}

View file

@ -1,9 +1,7 @@
//! Resource descriptior deserializer.
//!
//! # Specification
//!
//! - <https://datatracker.ietf.org/doc/html/rfc6415>
//! - <https://datatracker.ietf.org/doc/html/rfc7033>
//! [RFC 6415]: https://datatracker.ietf.org/doc/html/rfc6415
//! [RFC 7033]: https://datatracker.ietf.org/doc/html/rfc7033#section-4.4
use std::collections::HashMap;
@ -11,118 +9,105 @@ use serde::Deserialize;
/// A resource descriptor object.
///
/// # Specification
///
/// - <https://datatracker.ietf.org/doc/html/rfc6415#section-3>
/// - <https://datatracker.ietf.org/doc/html/rfc7033#section-4.4>
/// ## Specification
///
/// - https://datatracker.ietf.org/doc/html/rfc6415#section-3
/// - https://datatracker.ietf.org/doc/html/rfc7033#section-4.4
#[derive(Debug, Clone, Deserialize)]
pub struct ResourceDescriptor {
/// The resource this document refers to.
///
/// # Specification
///
/// - <https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.1>
/// ## Specification
///
/// - https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.1
#[serde(alias = "Subject")]
pub subject: Option<String>,
/// Other names the resource described by this document can be referred to.
///
/// # Specification
///
/// - <https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.2>
/// ## Specification
///
/// - https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.2
#[serde(alias = "Alias")]
pub aliases: Option<Vec<String>>,
/// Additional information about the resource described by this document.
///
/// # Specification
///
/// - <https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.3>
/// ## Specification
///
/// - https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.3
#[serde(alias = "Property")]
pub properties: Option<Vec<ResourceDescriptorProperty>>,
/// Links established between the [`Self::subject`] and other resources.
///
/// # Specification
///
/// - <https://datatracker.ietf.org/doc/html/rfc6415#section-3.1.1>
/// - <https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.4>
/// ## Specification
///
/// - https://datatracker.ietf.org/doc/html/rfc6415#section-3.1.1
/// - https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.4
#[serde(alias = "Link")]
pub links: Option<Vec<ResourceDescriptorLink>>,
}
/// A link element, which puts the subject resource in relation with another.
///
/// # Specification
///
/// - <https://datatracker.ietf.org/doc/html/rfc6415#section-3.1.1>
/// ## Specification
///
/// - https://datatracker.ietf.org/doc/html/rfc6415#section-3.1.1
#[derive(Debug, Clone, Deserialize)]
pub struct ResourceDescriptorLink {
/// The kind of relation established by the subject with the attached resource.
///
/// # Specification
///
/// - <https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.4.1>
/// ## Specification
///
/// https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.4.1
#[serde(alias = "@rel")]
pub rel: String,
/// The media type of the resource put in relation.
///
/// # Specification
///
/// - <https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.4.2>
/// ## Specification
///
/// - https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.4.2
#[serde(alias = "@type")]
pub r#type: Option<String>,
/// URI to the resource put in relation.
///
/// # Specification
///
/// - <https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.4.3>
/// ## Specification
///
/// - https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.4.3
#[serde(alias = "@href")]
pub href: Option<String>,
/// Titles of the resource put in relation in various languages.
///
/// # Specification
///
/// - <https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.4.4>
/// ## Specification
///
/// - https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.4.4
pub titles: Option<Vec<HashMap<String, String>>>,
/// Additional information about the resource put in relation.
///
/// # Specification
///
/// - <https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.4.5>
/// ## Specification
///
/// - https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.4.5
pub properties: Option<Vec<ResourceDescriptorProperty>>,
/// Template to fill to get the URL to resource-specific information.
///
/// # Specification
///
/// - <https://datatracker.ietf.org/doc/html/rfc6415#section-4.2>
/// ## Specification
///
/// - https://datatracker.ietf.org/doc/html/rfc6415#section-4.2
#[serde(alias = "@template")]
pub template: Option<String>,
}
/// A property element, which describes a certain aspect of the subject resource.
///
/// # Specification
///
/// - <https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.3>
/// ## Specification
///
/// - https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.3
#[derive(Debug, Clone, Deserialize)]
pub struct ResourceDescriptorProperty {
/// The property identifier, or type.
@ -136,11 +121,11 @@ pub struct ResourceDescriptorProperty {
impl ResourceDescriptor {
/// Get a JRD (JSON [`ResourceDescriptor`]).
///
/// # Notes
/// ## Notes
///
/// This follows redirects until the redirect chain is 10 hops; see [`reqwest::redirect`] for more info.
///
/// # Examples
/// ## Examples
///
/// ```
/// # tokio_test::block_on(async {
@ -206,11 +191,11 @@ impl ResourceDescriptor {
/// Get a XRD (Extensible [`ResourceDescriptor`]).
///
/// # Notes
/// ## Notes
///
/// This follows redirects until the redirect chain is 10 hops; see [`reqwest::redirect`] for more info.
///
/// # Examples
/// ## Examples
///
/// ```
/// # tokio_test::block_on(async {
@ -225,7 +210,6 @@ impl ResourceDescriptor {
/// .expect("XRD to be processed correctly");
/// # })
/// ```
///
pub async fn get_xrd(client: &reqwest::Client, url: reqwest::Url) -> Result<Self, GetXRDError> {
use GetXRDError::*;
@ -282,18 +266,18 @@ impl ResourceDescriptor {
///
/// In order, this method attempts:
///
/// 1. HTTPS [XRD](Self::get_xrd)
/// 2. HTTPS [JRD](Self::get_jrd)
/// 3. HTTPS [JRD](Self::get_jrd) with .json path extension
/// 4. HTTP [XRD](Self::get_xrd)
/// 5. HTTP [JRD](Self::get_jrd)
/// 6. HTTP [JRD](Self::get_jrd) with .json path extension
/// 1. [HTTPS] [XRD](Self::get_xrd)
/// 2. [HTTPS] [JRD](Self::get_jrd)
/// 3. [HTTPS] [JRD](Self::get_jrd) with .json path extension
/// 4. [HTTP] [XRD](Self::get_xrd)
/// 5. [HTTP] [JRD](Self::get_jrd)
/// 6. [HTTP] [JRD](Self::get_jrd) with .json path extension
///
/// # Notes
/// ## Notes
///
/// This follows redirects until the redirect chain is 10 hops; see [`reqwest::redirect`] for more info.
///
/// # Examples
/// ## Examples
///
/// ```
/// # tokio_test::block_on(async {
@ -444,15 +428,14 @@ impl ResourceDescriptor {
/// Well-known path for host-meta documents.
///
/// # Specification
///
/// - <https://datatracker.ietf.org/doc/html/rfc6415#section-2>
/// ## Specification
///
/// - https://datatracker.ietf.org/doc/html/rfc6415#section-2
pub const WELLKNOWN_HOSTMETA_PATH: &str = "/.well-known/host-meta";
/// Attempt to discover a host-meta document at the given base URL.
///
/// # Examples
/// ## Examples
///
/// ```
/// # tokio_test::block_on(async {

View file

@ -1,18 +1,14 @@
//! Serde-based NodeInfo fetcher and loose parser.
//!
//! > NodeInfo is an effort to create a standardized way of exposing metadata about a server running one of the distributed social networks.
//!
//! # Specification
//!
//! - <https://github.com/jhass/nodeinfo/blob/main/PROTOCOL.md>
use serde::Deserialize;
/// A variant of a NodeInfo document.
///
/// # Specification
/// ## Specification
///
/// - <https://github.com/jhass/nodeinfo/blob/main/PROTOCOL.md>
/// - https://github.com/jhass/nodeinfo/blob/main/PROTOCOL.md
#[derive(Debug, Clone)]
pub enum NodeInfo {
V1(NodeInfo1),
@ -21,10 +17,10 @@ pub enum NodeInfo {
/// A NodeInfo document at version 1.X.
///
/// # Specification
/// ## Specification
///
/// - <https://github.com/jhass/nodeinfo/blob/main/schemas/1.0/schema.json>
/// - <https://github.com/jhass/nodeinfo/blob/main/schemas/1.1/schema.json>
/// - https://github.com/jhass/nodeinfo/blob/main/schemas/1.0/schema.json
/// - https://github.com/jhass/nodeinfo/blob/main/schemas/1.1/schema.json
///
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
@ -55,11 +51,11 @@ pub struct NodeInfo1 {
/// A NodeInfo document at version 2.X.
///
/// # Specification
/// ## Specification
///
/// - <https://github.com/jhass/nodeinfo/blob/main/schemas/2.0/schema.json>
/// - <https://github.com/jhass/nodeinfo/blob/main/schemas/2.1/schema.json>
/// - <https://github.com/jhass/nodeinfo/blob/main/schemas/2.2/schema.json>
/// - https://github.com/jhass/nodeinfo/blob/main/schemas/2.0/schema.json
/// - https://github.com/jhass/nodeinfo/blob/main/schemas/2.1/schema.json
/// - https://github.com/jhass/nodeinfo/blob/main/schemas/2.2/schema.json
///
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
@ -167,14 +163,14 @@ pub struct NodeInfo2Instance {
impl NodeInfo {
/// Well-known path for NodeInfo documents.
///
/// # Specification
/// ## Specification
///
/// - <https://github.com/jhass/nodeinfo/blob/main/PROTOCOL.md#discovery>
/// - https://github.com/jhass/nodeinfo/blob/main/PROTOCOL.md#discovery
pub const WELLKNOWN_NODEINFO_PATH: &str = "/.well-known/nodeinfo";
/// Discover and get the latest NodeInfo version available given a certain base URL.
///
/// # Examples
/// ## Examples
///
/// ```
/// # tokio_test::block_on(async {
@ -375,7 +371,7 @@ impl NodeInfo1 {
impl NodeInfo2 {
/// Get a NodeInfo v2.X document.
///
/// # Examples
/// ## Examples
///
/// ```
/// # tokio_test::block_on(async {