-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use std::collections::{BTreeMap, BTreeSet}; | ||
|
||
use exver::{PreReleaseSegment, VersionRange}; | ||
use imbl_value::InternedString; | ||
use serde::{Deserialize, Serialize}; | ||
use torut::onion::OnionAddressV3; | ||
|
||
use super::v0_3_5::V0_3_0_COMPAT; | ||
use super::{v0_3_6_alpha_9, VersionT}; | ||
use crate::db::model::Database; | ||
use crate::net::host::address::DomainConfig; | ||
use crate::prelude::*; | ||
|
||
lazy_static::lazy_static! { | ||
static ref V0_3_6_alpha_10: exver::Version = exver::Version::new( | ||
[0, 3, 6], | ||
[PreReleaseSegment::String("alpha".into()), 10.into()] | ||
); | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)] | ||
#[serde(rename_all = "camelCase")] | ||
#[serde(tag = "kind")] | ||
enum HostAddress { | ||
Onion { address: OnionAddressV3 }, | ||
Domain { address: InternedString }, | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Default)] | ||
pub struct Version; | ||
|
||
impl VersionT for Version { | ||
type Previous = v0_3_6_alpha_9::Version; | ||
type PreUpRes = (); | ||
|
||
async fn pre_up(self) -> Result<Self::PreUpRes, Error> { | ||
Ok(()) | ||
} | ||
fn semver(self) -> exver::Version { | ||
V0_3_6_alpha_10.clone() | ||
} | ||
fn compat(self) -> &'static VersionRange { | ||
&V0_3_0_COMPAT | ||
} | ||
fn up(self, db: &mut Value, _: Self::PreUpRes) -> Result<(), Error> { | ||
for (package, data) in db["public"]["packageData"] | ||
.as_object_mut() | ||
.ok_or_else(|| { | ||
Error::new( | ||
eyre!("expected public.packageData to be an object"), | ||
ErrorKind::Database, | ||
) | ||
})? | ||
.iter_mut() | ||
{ | ||
for (host_id, host) in data["hosts"] | ||
.as_object_mut() | ||
.ok_or_else(|| { | ||
Error::new( | ||
eyre!("expected public.packageData to be an object"), | ||
ErrorKind::Database, | ||
) | ||
})? | ||
.iter_mut() | ||
{ | ||
let mut onions = BTreeSet::new(); | ||
let mut domains = BTreeMap::new(); | ||
let addresses = from_value::<BTreeSet<HostAddress>>(host["addresses"].clone())?; | ||
for address in addresses { | ||
match address { | ||
HostAddress::Onion { address } => { | ||
onions.insert(address); | ||
} | ||
HostAddress::Domain { address } => { | ||
domains.insert( | ||
address, | ||
DomainConfig { | ||
public: true, | ||
acme: None, | ||
}, | ||
); | ||
} | ||
} | ||
} | ||
host["onions"] = to_value(&onions)?; | ||
host["domains"] = to_value(&domains)?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
fn down(self, _db: &mut Value) -> Result<(), Error> { | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters