Define proxy origin
This commit is contained in:
parent
5dd2e756cc
commit
c336486f5a
@ -7,6 +7,7 @@ use sha2::{Digest, Sha256};
|
|||||||
/// A unique description of an origin, from where a domain might be served.
|
/// A unique description of an origin, from where a domain might be served.
|
||||||
pub enum Descr {
|
pub enum Descr {
|
||||||
Git { url: String, branch_name: String },
|
Git { url: String, branch_name: String },
|
||||||
|
Proxy { url: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Descr {
|
impl Descr {
|
||||||
@ -25,6 +26,10 @@ impl Descr {
|
|||||||
h_update(url);
|
h_update(url);
|
||||||
h_update(branch_name);
|
h_update(branch_name);
|
||||||
}
|
}
|
||||||
|
Descr::Proxy { url } => {
|
||||||
|
h_update("proxy");
|
||||||
|
h_update(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
h.finalize().encode_hex::<String>()
|
h.finalize().encode_hex::<String>()
|
||||||
|
@ -56,15 +56,24 @@ impl FSStore {
|
|||||||
format!("origin/{branch_name}")
|
format!("origin/{branch_name}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deconstruct_descr(descr: &origin::Descr) -> (&str, &str) {
|
||||||
|
if let origin::Descr::Git {
|
||||||
|
ref url,
|
||||||
|
ref branch_name,
|
||||||
|
} = descr
|
||||||
|
{
|
||||||
|
(url, branch_name)
|
||||||
|
} else {
|
||||||
|
panic!("non git descr passed in")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn create_repo_snapshot(
|
fn create_repo_snapshot(
|
||||||
&self,
|
&self,
|
||||||
repo: gix::Repository,
|
repo: gix::Repository,
|
||||||
descr: &origin::Descr,
|
descr: &origin::Descr,
|
||||||
) -> Result<RepoSnapshot, CreateRepoSnapshotError> {
|
) -> Result<RepoSnapshot, CreateRepoSnapshotError> {
|
||||||
let origin::Descr::Git {
|
let (_, branch_name) = Self::deconstruct_descr(descr);
|
||||||
ref branch_name, ..
|
|
||||||
} = descr;
|
|
||||||
|
|
||||||
let branch_ref = self.branch_ref(branch_name);
|
let branch_ref = self.branch_ref(branch_name);
|
||||||
|
|
||||||
let commit_object_id = repo
|
let commit_object_id = repo
|
||||||
@ -148,10 +157,7 @@ impl FSStore {
|
|||||||
fs::create_dir_all(repo_path)
|
fs::create_dir_all(repo_path)
|
||||||
.map_unexpected_while(|| format!("creating {}", repo_path.display()))?;
|
.map_unexpected_while(|| format!("creating {}", repo_path.display()))?;
|
||||||
|
|
||||||
let origin::Descr::Git {
|
let (url, branch_name) = Self::deconstruct_descr(descr);
|
||||||
ref url,
|
|
||||||
ref branch_name,
|
|
||||||
} = descr;
|
|
||||||
|
|
||||||
let (repo, _) = gix::prepare_clone_bare(url.clone(), repo_path)
|
let (repo, _) = gix::prepare_clone_bare(url.clone(), repo_path)
|
||||||
.map_err(|e| match e {
|
.map_err(|e| match e {
|
||||||
|
@ -257,8 +257,7 @@ impl<'svc> Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let settings: domain::Settings = match args.flat_domain_settings.try_into() {
|
let settings: domain::Settings = match args.flat_domain_settings.try_into() {
|
||||||
Ok(Some(settings)) => settings,
|
Ok(settings) => settings,
|
||||||
Ok(None) => return self.render_error_page(400, "no domain settings provided"),
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return self
|
return self
|
||||||
.render_error_page(400, format!("invalid domain settings: {e}").as_str())
|
.render_error_page(400, format!("invalid domain settings: {e}").as_str())
|
||||||
@ -280,11 +279,19 @@ impl<'svc> Service {
|
|||||||
_ => false,
|
_ => false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let flat_domain_settings = match settings.try_into() {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(e) => {
|
||||||
|
return self
|
||||||
|
.internal_error(format!("failed to flatten domains settings: {e}").as_str())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
self.render_page(
|
self.render_page(
|
||||||
"/domain_init.html",
|
"/domain_init.html",
|
||||||
Data {
|
Data {
|
||||||
domain: args.domain,
|
domain: args.domain,
|
||||||
flat_domain_settings: settings.into(),
|
flat_domain_settings,
|
||||||
dns_records: &self.config.dns_records,
|
dns_records: &self.config.dns_records,
|
||||||
challenge_token: settings_hash,
|
challenge_token: settings_hash,
|
||||||
|
|
||||||
@ -300,8 +307,7 @@ impl<'svc> Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let settings: domain::Settings = match args.flat_domain_settings.try_into() {
|
let settings: domain::Settings = match args.flat_domain_settings.try_into() {
|
||||||
Ok(Some(settings)) => settings,
|
Ok(settings) => settings,
|
||||||
Ok(None) => return self.render_error_page(400, "no domain settings provided"),
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return self
|
return self
|
||||||
.render_error_page(400, format!("invalid domain settings: {e}").as_str())
|
.render_error_page(400, format!("invalid domain settings: {e}").as_str())
|
||||||
|
@ -1,49 +1,58 @@
|
|||||||
use std::convert::{From, TryFrom};
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{domain, origin};
|
use crate::{domain, error::unexpected, origin};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Default)]
|
||||||
pub struct FlatDomainSettings {
|
pub struct FlatDomainSettings {
|
||||||
domain_setting_origin_descr_kind: Option<String>,
|
domain_setting_origin_descr_kind: Option<String>,
|
||||||
|
|
||||||
domain_setting_origin_descr_git_url: Option<String>,
|
domain_setting_origin_descr_git_url: Option<String>,
|
||||||
domain_setting_origin_descr_git_branch_name: Option<String>,
|
domain_setting_origin_descr_git_branch_name: Option<String>,
|
||||||
|
|
||||||
|
domain_setting_origin_descr_proxy_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<FlatDomainSettings> for Option<domain::Settings> {
|
impl TryFrom<FlatDomainSettings> for domain::Settings {
|
||||||
type Error = String;
|
type Error = String;
|
||||||
|
|
||||||
fn try_from(v: FlatDomainSettings) -> Result<Self, Self::Error> {
|
fn try_from(v: FlatDomainSettings) -> Result<Self, Self::Error> {
|
||||||
match v
|
let origin_descr = match v
|
||||||
.domain_setting_origin_descr_kind
|
.domain_setting_origin_descr_kind
|
||||||
.unwrap_or("".to_string())
|
.unwrap_or("".to_string())
|
||||||
.as_str()
|
.as_str()
|
||||||
{
|
{
|
||||||
"" => Ok(None),
|
"git" => Ok(origin::Descr::Git {
|
||||||
"git" => Ok(Some(domain::Settings {
|
url: v
|
||||||
origin_descr: origin::Descr::Git {
|
.domain_setting_origin_descr_git_url
|
||||||
url: v
|
.ok_or("missing domain_setting_origin_descr_git_url")?,
|
||||||
.domain_setting_origin_descr_git_url
|
branch_name: v
|
||||||
.ok_or("domain_setting_origin_descr_git_url missing")?,
|
.domain_setting_origin_descr_git_branch_name
|
||||||
branch_name: v
|
.ok_or("missing domain_setting_origin_descr_git_branch_name")?,
|
||||||
.domain_setting_origin_descr_git_branch_name
|
}),
|
||||||
.ok_or("domain_setting_origin_descr_git_branch_name missing")?,
|
"" => Err("missing domain_setting_origin_descr_kind".to_string()),
|
||||||
},
|
|
||||||
})),
|
|
||||||
_ => Err("invalid domain_setting_origin_descr_kind".to_string()),
|
_ => Err("invalid domain_setting_origin_descr_kind".to_string()),
|
||||||
}
|
}?;
|
||||||
|
|
||||||
|
Ok(Self { origin_descr })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<domain::Settings> for FlatDomainSettings {
|
impl TryFrom<domain::Settings> for FlatDomainSettings {
|
||||||
fn from(v: domain::Settings) -> Self {
|
type Error = unexpected::Error;
|
||||||
|
|
||||||
|
fn try_from(v: domain::Settings) -> Result<Self, Self::Error> {
|
||||||
match v.origin_descr {
|
match v.origin_descr {
|
||||||
origin::Descr::Git { url, branch_name } => FlatDomainSettings {
|
origin::Descr::Git { url, branch_name } => Ok(FlatDomainSettings {
|
||||||
domain_setting_origin_descr_kind: Some("git".to_string()),
|
domain_setting_origin_descr_kind: Some("git".to_string()),
|
||||||
domain_setting_origin_descr_git_url: Some(url),
|
domain_setting_origin_descr_git_url: Some(url),
|
||||||
domain_setting_origin_descr_git_branch_name: Some(branch_name),
|
domain_setting_origin_descr_git_branch_name: Some(branch_name),
|
||||||
},
|
..Default::default()
|
||||||
|
}),
|
||||||
|
origin::Descr::Proxy { .. } => Err(unexpected::Error::from(
|
||||||
|
"proxy origins not supported for forms",
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user