Skip to content

Commit

Permalink
migration
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bonez committed Dec 18, 2024
1 parent 926ef71 commit 5908ec4
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 11 deletions.
7 changes: 6 additions & 1 deletion core/startos/src/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ mod v0_3_6_alpha_7;
mod v0_3_6_alpha_8;
mod v0_3_6_alpha_9;

pub type Current = v0_3_6_alpha_9::Version; // VERSION_BUMP
mod v0_3_6_alpha_10;

pub type Current = v0_3_6_alpha_10::Version; // VERSION_BUMP

impl Current {
#[instrument(skip(self, db))]
Expand Down Expand Up @@ -108,6 +110,7 @@ enum Version {
V0_3_6_alpha_7(Wrapper<v0_3_6_alpha_7::Version>),
V0_3_6_alpha_8(Wrapper<v0_3_6_alpha_8::Version>),
V0_3_6_alpha_9(Wrapper<v0_3_6_alpha_9::Version>),
V0_3_6_alpha_10(Wrapper<v0_3_6_alpha_10::Version>),
Other(exver::Version),
}

Expand Down Expand Up @@ -141,6 +144,7 @@ impl Version {
Self::V0_3_6_alpha_7(v) => DynVersion(Box::new(v.0)),
Self::V0_3_6_alpha_8(v) => DynVersion(Box::new(v.0)),
Self::V0_3_6_alpha_9(v) => DynVersion(Box::new(v.0)),
Self::V0_3_6_alpha_10(v) => DynVersion(Box::new(v.0)),
Self::Other(v) => {
return Err(Error::new(
eyre!("unknown version {v}"),
Expand All @@ -166,6 +170,7 @@ impl Version {
Version::V0_3_6_alpha_7(Wrapper(x)) => x.semver(),
Version::V0_3_6_alpha_8(Wrapper(x)) => x.semver(),
Version::V0_3_6_alpha_9(Wrapper(x)) => x.semver(),
Version::V0_3_6_alpha_10(Wrapper(x)) => x.semver(),
Version::Other(x) => x.clone(),
}
}
Expand Down
95 changes: 95 additions & 0 deletions core/startos/src/version/v0_3_6_alpha_10.rs
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(())
}
}
11 changes: 1 addition & 10 deletions sdk/base/lib/util/getServiceInterface.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { ServiceInterfaceType } from "../types"
import { knownProtocols } from "../interfaces/Host"
import {
AddressInfo,
Host,
HostAddress,
Hostname,
HostnameInfo,
HostnameInfoIp,
HostnameInfoOnion,
IpInfo,
} from "../types"
import { AddressInfo, Host, Hostname, HostnameInfo } from "../types"
import { Effects } from "../Effects"

export type UrlString = string
Expand Down

0 comments on commit 5908ec4

Please sign in to comment.