From 5a4ff4ca65391695735e81f805fc241b07e85503 Mon Sep 17 00:00:00 2001
From: Brian Picciano
Date: Sun, 16 Jul 2023 13:55:06 +0200
Subject: [PATCH] Add secret service.http.form_method field for debugging
---
.dev-config.yml | 2 +
src/domain/config.rs | 1 +
src/service.rs | 37 +---------
src/service/config.rs | 35 +++++++++
src/service/http.rs | 102 +++++++++++++++-----------
src/service/http/config.rs | 34 +++++++++
src/service/http/tpl/domain.html | 2 +-
src/service/http/tpl/domain_init.html | 4 +-
src/service/http/tpl/index.html | 2 +-
9 files changed, 139 insertions(+), 80 deletions(-)
create mode 100644 src/service/config.rs
diff --git a/.dev-config.yml b/.dev-config.yml
index 8557b56..df4a59c 100644
--- a/.dev-config.yml
+++ b/.dev-config.yml
@@ -3,6 +3,8 @@ origin:
domain:
store_dir_path: /tmp/domani_dev_env/domain
service:
+ http:
+ form_method: GET
passphrase: foobar
dns_records:
- kind: A
diff --git a/src/domain/config.rs b/src/domain/config.rs
index 22352f1..a346025 100644
--- a/src/domain/config.rs
+++ b/src/domain/config.rs
@@ -41,5 +41,6 @@ pub struct Config {
#[serde(default)]
pub dns: ConfigDNS,
pub acme: Option,
+ #[serde(default)]
pub builtins: collections::HashMap,
}
diff --git a/src/service.rs b/src/service.rs
index af5f4f1..82ec5be 100644
--- a/src/service.rs
+++ b/src/service.rs
@@ -1,38 +1,5 @@
+mod config;
pub mod http;
mod util;
-use crate::domain;
-use serde::{Deserialize, Serialize};
-use std::{net, str::FromStr};
-
-fn default_primary_domain() -> domain::Name {
- domain::Name::from_str("localhost").unwrap()
-}
-
-#[derive(Serialize, Deserialize, Clone, PartialEq)]
-#[serde(tag = "kind")]
-pub enum ConfigDNSRecord {
- A { addr: net::Ipv4Addr },
- AAAA { addr: net::Ipv6Addr },
- CNAME { name: domain::Name },
-}
-
-impl From for domain::checker::DNSRecord {
- fn from(r: ConfigDNSRecord) -> Self {
- match r {
- ConfigDNSRecord::A { addr } => Self::A(addr),
- ConfigDNSRecord::AAAA { addr } => Self::AAAA(addr),
- ConfigDNSRecord::CNAME { name } => Self::CNAME(name),
- }
- }
-}
-
-#[derive(Deserialize)]
-pub struct Config {
- pub passphrase: String,
- pub dns_records: Vec,
- #[serde(default = "default_primary_domain")]
- pub primary_domain: domain::Name,
- #[serde(default)]
- pub http: self::http::Config,
-}
+pub use config::*;
diff --git a/src/service/config.rs b/src/service/config.rs
new file mode 100644
index 0000000..f8f11d2
--- /dev/null
+++ b/src/service/config.rs
@@ -0,0 +1,35 @@
+use crate::{domain, service};
+use serde::{Deserialize, Serialize};
+use std::{net, str::FromStr};
+
+fn default_primary_domain() -> domain::Name {
+ domain::Name::from_str("localhost").unwrap()
+}
+
+#[derive(Serialize, Deserialize, Clone, PartialEq)]
+#[serde(tag = "kind")]
+pub enum ConfigDNSRecord {
+ A { addr: net::Ipv4Addr },
+ AAAA { addr: net::Ipv6Addr },
+ CNAME { name: domain::Name },
+}
+
+impl From for domain::checker::DNSRecord {
+ fn from(r: ConfigDNSRecord) -> Self {
+ match r {
+ ConfigDNSRecord::A { addr } => Self::A(addr),
+ ConfigDNSRecord::AAAA { addr } => Self::AAAA(addr),
+ ConfigDNSRecord::CNAME { name } => Self::CNAME(name),
+ }
+ }
+}
+
+#[derive(Deserialize)]
+pub struct Config {
+ pub passphrase: String,
+ pub dns_records: Vec,
+ #[serde(default = "default_primary_domain")]
+ pub primary_domain: domain::Name,
+ #[serde(default)]
+ pub http: service::http::Config,
+}
diff --git a/src/service/http.rs b/src/service/http.rs
index e8bbb3d..af3d492 100644
--- a/src/service/http.rs
+++ b/src/service/http.rs
@@ -4,6 +4,7 @@ mod tpl;
pub use config::*;
+use http::request::Parts;
use hyper::{Body, Method, Request, Response};
use serde::{Deserialize, Serialize};
@@ -48,6 +49,7 @@ pub fn new(
#[derive(Serialize)]
struct BasePresenter<'a, T> {
page_name: &'a str,
+ form_method: &'a str,
data: T,
}
@@ -59,12 +61,18 @@ struct DomainGetArgs {
#[derive(Deserialize)]
struct DomainInitArgs {
domain: domain::Name,
+
+ #[serde(flatten)]
+ domain_config: service::util::FlatConfig,
}
#[derive(Deserialize)]
struct DomainSyncArgs {
domain: domain::Name,
passphrase: String,
+
+ #[serde(flatten)]
+ domain_config: service::util::FlatConfig,
}
impl<'svc> Service {
@@ -121,6 +129,7 @@ impl<'svc> Service {
"/base.html",
BasePresenter {
page_name: "/error.html",
+ form_method: self.config.http.form_method.as_str(),
data: &Response { error_msg: e },
},
)
@@ -143,6 +152,7 @@ impl<'svc> Service {
"/base.html",
BasePresenter {
page_name: name,
+ form_method: self.config.http.form_method.as_str(),
data,
},
)
@@ -174,14 +184,33 @@ impl<'svc> Service {
}
}
- async fn with_query_req<'a, F, In, Out>(&self, req: &'a Request, f: F) -> Response
+ async fn with_query_req<'a, F, In, Out>(
+ &self,
+ req: &'a Parts,
+ body: Body,
+ f: F,
+ ) -> Response
where
- In: Deserialize<'a>,
+ In: for<'d> Deserialize<'d>,
F: FnOnce(In) -> Out,
Out: future::Future
In the future Domani will support more backends than just git
repos.
-