mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
update types
This commit is contained in:
@@ -20,7 +20,7 @@ use crate::db::model::package::AllPackageData;
|
||||
use crate::net::acme::AcmeProvider;
|
||||
use crate::net::forward::START9_BRIDGE_IFACE;
|
||||
use crate::net::host::binding::{AddSslOptions, BindInfo, BindOptions, NetInfo};
|
||||
use crate::net::host::{Domains, Host};
|
||||
use crate::net::host::Host;
|
||||
use crate::net::utils::ipv6_is_local;
|
||||
use crate::net::vhost::AlpnInfo;
|
||||
use crate::prelude::*;
|
||||
@@ -82,7 +82,8 @@ impl Public {
|
||||
.into_iter()
|
||||
.collect(),
|
||||
onions: account.tor_keys.iter().map(|k| k.onion_address()).collect(),
|
||||
domains: Domains::default(),
|
||||
public_domains: BTreeMap::new(),
|
||||
private_domains: BTreeSet::new(),
|
||||
hostname_info: BTreeMap::new(),
|
||||
},
|
||||
wifi: WifiInfo {
|
||||
|
||||
@@ -88,8 +88,7 @@ impl SignatureAuthContext for RpcContext {
|
||||
.as_server_info()
|
||||
.as_network()
|
||||
.as_host()
|
||||
.as_domains()
|
||||
.as_public()
|
||||
.as_public_domains()
|
||||
.keys()
|
||||
.map(|k| k.into_iter())
|
||||
.transpose(),
|
||||
@@ -99,8 +98,7 @@ impl SignatureAuthContext for RpcContext {
|
||||
.as_server_info()
|
||||
.as_network()
|
||||
.as_host()
|
||||
.as_domains()
|
||||
.as_private()
|
||||
.as_private_domains()
|
||||
.de()
|
||||
.map(|k| k.into_iter())
|
||||
.transpose(),
|
||||
|
||||
@@ -63,10 +63,10 @@ fn check_duplicates(db: &DatabaseModel) -> Result<(), Error> {
|
||||
for onion in host.as_onions().de()? {
|
||||
check_onion(onion)?;
|
||||
}
|
||||
for domain in host.as_domains().as_public().keys()? {
|
||||
for domain in host.as_public_domains().keys()? {
|
||||
check_domain(domain)?;
|
||||
}
|
||||
for domain in host.as_domains().as_private().de()? {
|
||||
for domain in host.as_private_domains().de()? {
|
||||
check_domain(domain)?;
|
||||
}
|
||||
}
|
||||
@@ -230,8 +230,7 @@ pub async fn add_public_domain<Kind: HostApiKind>(
|
||||
}
|
||||
|
||||
Kind::host_for(&inheritance, db)?
|
||||
.as_domains_mut()
|
||||
.as_public_mut()
|
||||
.as_public_domains_mut()
|
||||
.insert(domain, &PublicDomainConfig { acme, gateway })?;
|
||||
check_duplicates(db)
|
||||
})
|
||||
@@ -255,8 +254,7 @@ pub async fn remove_public_domain<Kind: HostApiKind>(
|
||||
ctx.db
|
||||
.mutate(|db| {
|
||||
Kind::host_for(&inheritance, db)?
|
||||
.as_domains_mut()
|
||||
.as_public_mut()
|
||||
.as_public_domains_mut()
|
||||
.remove(&domain)
|
||||
})
|
||||
.await
|
||||
@@ -279,8 +277,7 @@ pub async fn add_private_domain<Kind: HostApiKind>(
|
||||
ctx.db
|
||||
.mutate(|db| {
|
||||
Kind::host_for(&inheritance, db)?
|
||||
.as_domains_mut()
|
||||
.as_private_mut()
|
||||
.as_private_domains_mut()
|
||||
.mutate(|d| Ok(d.insert(domain)))?;
|
||||
check_duplicates(db)
|
||||
})
|
||||
@@ -299,8 +296,7 @@ pub async fn remove_private_domain<Kind: HostApiKind>(
|
||||
ctx.db
|
||||
.mutate(|db| {
|
||||
Kind::host_for(&inheritance, db)?
|
||||
.as_domains_mut()
|
||||
.as_private_mut()
|
||||
.as_private_domains_mut()
|
||||
.mutate(|d| Ok(d.remove(&domain)))
|
||||
})
|
||||
.await
|
||||
|
||||
@@ -30,22 +30,12 @@ pub struct Host {
|
||||
pub bindings: BTreeMap<u16, BindInfo>,
|
||||
#[ts(type = "string[]")]
|
||||
pub onions: BTreeSet<OnionAddress>,
|
||||
pub domains: Domains,
|
||||
pub public_domains: BTreeMap<InternedString, PublicDomainConfig>,
|
||||
pub private_domains: BTreeSet<InternedString>,
|
||||
/// COMPUTED: NetService::update
|
||||
pub hostname_info: BTreeMap<u16, Vec<HostnameInfo>>, // internal port -> Hostnames
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, HasModel, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[model = "Model<Self>"]
|
||||
#[ts(export)]
|
||||
pub struct Domains {
|
||||
#[ts(as = "BTreeMap::<String, PublicDomainConfig>")]
|
||||
pub public: BTreeMap<InternedString, PublicDomainConfig>,
|
||||
#[ts(as = "BTreeSet::<String>")]
|
||||
pub private: BTreeSet<InternedString>,
|
||||
}
|
||||
|
||||
impl AsRef<Host> for Host {
|
||||
fn as_ref(&self) -> &Host {
|
||||
self
|
||||
@@ -61,8 +51,7 @@ impl Host {
|
||||
.cloned()
|
||||
.map(|address| HostAddress::Onion { address })
|
||||
.chain(
|
||||
self.domains
|
||||
.public
|
||||
self.public_domains
|
||||
.iter()
|
||||
.map(|(address, config)| HostAddress::Domain {
|
||||
address: address.clone(),
|
||||
@@ -70,8 +59,7 @@ impl Host {
|
||||
}),
|
||||
)
|
||||
.chain(
|
||||
self.domains
|
||||
.private
|
||||
self.private_domains
|
||||
.iter()
|
||||
.map(|address| HostAddress::Domain {
|
||||
address: address.clone(),
|
||||
|
||||
@@ -59,8 +59,8 @@ pub async fn get_ssl_certificate(
|
||||
.de()?
|
||||
.iter()
|
||||
.map(InternedString::from_display)
|
||||
.chain(m.as_domains().as_public().keys()?)
|
||||
.chain(m.as_domains().as_private().de()?)
|
||||
.chain(m.as_public_domains().keys()?)
|
||||
.chain(m.as_private_domains().de()?)
|
||||
.chain(
|
||||
m.as_hostname_info()
|
||||
.de()?
|
||||
@@ -185,8 +185,8 @@ pub async fn get_ssl_key(
|
||||
.de()?
|
||||
.iter()
|
||||
.map(InternedString::from_display)
|
||||
.chain(m.as_domains().as_public().keys()?)
|
||||
.chain(m.as_domains().as_private().de()?)
|
||||
.chain(m.as_public_domains().keys()?)
|
||||
.chain(m.as_private_domains().de()?)
|
||||
.chain(
|
||||
m.as_hostname_info()
|
||||
.de()?
|
||||
|
||||
@@ -87,7 +87,8 @@ impl VersionT for Version {
|
||||
}
|
||||
|
||||
}
|
||||
host["domains"] = json!({ "public": &public, "private": &private });
|
||||
host["publicDomains"] = to_value(&public)?;
|
||||
host["privateDomains"] = to_value(&private)?;
|
||||
}
|
||||
}
|
||||
let network = &mut db["public"]["serverInfo"]["network"];
|
||||
|
||||
Reference in New Issue
Block a user