mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-01 21:13:09 +00:00
Merge branch 'next/minor' of github.com:Start9Labs/start-os into next/major
This commit is contained in:
@@ -8,7 +8,7 @@ use sqlx::PgPool;
|
||||
use crate::prelude::*;
|
||||
use crate::Error;
|
||||
|
||||
mod v0_3_5;
|
||||
mod v0_3_5_1;
|
||||
mod v0_4_0;
|
||||
|
||||
pub type Current = v0_4_0::Version;
|
||||
@@ -16,8 +16,8 @@ pub type Current = v0_4_0::Version;
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
|
||||
#[serde(untagged)]
|
||||
enum Version {
|
||||
LT0_3_5(LTWrapper<v0_3_5::Version>),
|
||||
V0_3_5(Wrapper<v0_3_5::Version>),
|
||||
LT0_3_5_1(LTWrapper<v0_3_5_1::Version>),
|
||||
V0_3_5_1(Wrapper<v0_3_5_1::Version>),
|
||||
V0_4_0(Wrapper<v0_4_0::Version>),
|
||||
Other(emver::Version),
|
||||
}
|
||||
@@ -34,8 +34,8 @@ impl Version {
|
||||
#[cfg(test)]
|
||||
fn as_sem_ver(&self) -> emver::Version {
|
||||
match self {
|
||||
Version::LT0_3_5(LTWrapper(_, x)) => x.clone(),
|
||||
Version::V0_3_5(Wrapper(x)) => x.semver(),
|
||||
Version::LT0_3_5_1(LTWrapper(_, x)) => x.clone(),
|
||||
Version::V0_3_5_1(Wrapper(x)) => x.semver(),
|
||||
Version::V0_4_0(Wrapper(x)) => x.semver(),
|
||||
Version::Other(x) => x.clone(),
|
||||
}
|
||||
@@ -182,13 +182,13 @@ pub async fn init(db: &PatchDb, secrets: &PgPool) -> Result<(), Error> {
|
||||
let version = Version::from_util_version(db.peek().await.as_server_info().as_version().de()?);
|
||||
|
||||
match version {
|
||||
Version::LT0_3_5(_) => {
|
||||
Version::LT0_3_5_1(_) => {
|
||||
return Err(Error::new(
|
||||
eyre!("Cannot migrate from pre-0.3.5. Please update to v0.3.5 first."),
|
||||
eyre!("Cannot migrate from pre-0.3.5.1. Please update to v0.3.5.1 first."),
|
||||
crate::ErrorKind::MigrationFailed,
|
||||
));
|
||||
}
|
||||
Version::V0_3_5(v) => v.0.migrate_to(&Current::new(), db, secrets).await?,
|
||||
Version::V0_3_5_1(v) => v.0.migrate_to(&Current::new(), db, secrets).await?,
|
||||
Version::V0_4_0(v) => v.0.migrate_to(&Current::new(), db, secrets).await?,
|
||||
Version::Other(_) => {
|
||||
return Err(Error::new(
|
||||
@@ -222,15 +222,15 @@ mod tests {
|
||||
|
||||
fn versions() -> impl Strategy<Value = Version> {
|
||||
prop_oneof![
|
||||
em_version().prop_map(|v| if v < v0_3_5::Version::new().semver() {
|
||||
Version::LT0_3_5(LTWrapper(v0_3_5::Version::new(), v))
|
||||
em_version().prop_map(|v| if v < v0_3_5_1::Version::new().semver() {
|
||||
Version::LT0_3_5_1(LTWrapper(v0_3_5_1::Version::new(), v))
|
||||
} else {
|
||||
Version::LT0_3_5(LTWrapper(
|
||||
v0_3_5::Version::new(),
|
||||
Version::LT0_3_5_1(LTWrapper(
|
||||
v0_3_5_1::Version::new(),
|
||||
emver::Version::new(0, 3, 0, 0),
|
||||
))
|
||||
}),
|
||||
Just(Version::V0_3_5(Wrapper(v0_3_5::Version::new()))),
|
||||
Just(Version::V0_3_5_1(Wrapper(v0_3_5_1::Version::new()))),
|
||||
Just(Version::V0_4_0(Wrapper(v0_4_0::Version::new()))),
|
||||
em_version().prop_map(Version::Other),
|
||||
]
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
use async_trait::async_trait;
|
||||
use emver::VersionRange;
|
||||
use itertools::Itertools;
|
||||
use openssl::hash::MessageDigest;
|
||||
use serde_json::json;
|
||||
use ssh_key::public::Ed25519PublicKey;
|
||||
|
||||
use super::*;
|
||||
use crate::account::AccountInfo;
|
||||
use crate::hostname::{sync_hostname, Hostname};
|
||||
use crate::prelude::*;
|
||||
|
||||
const V0_3_4: emver::Version = emver::Version::new(0, 3, 4, 0);
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref V0_3_0_COMPAT: VersionRange = VersionRange::Conj(
|
||||
Box::new(VersionRange::Anchor(
|
||||
emver::GTE,
|
||||
emver::Version::new(0, 3, 0, 0),
|
||||
)),
|
||||
Box::new(VersionRange::Anchor(emver::LTE, Current::new().semver())),
|
||||
);
|
||||
}
|
||||
|
||||
const COMMUNITY_URL: &str = "https://community-registry.start9.com/";
|
||||
const MAIN_REGISTRY: &str = "https://registry.start9.com/";
|
||||
const COMMUNITY_SERVICES: &[&str] = &[
|
||||
"ipfs",
|
||||
"agora",
|
||||
"lightning-jet",
|
||||
"balanceofsatoshis",
|
||||
"mastodon",
|
||||
"lndg",
|
||||
"robosats",
|
||||
"thunderhub",
|
||||
"syncthing",
|
||||
"sphinx-relay",
|
||||
];
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Version;
|
||||
|
||||
#[async_trait]
|
||||
impl VersionT for Version {
|
||||
type Previous = Self;
|
||||
fn new() -> Self {
|
||||
Version
|
||||
}
|
||||
fn semver(&self) -> emver::Version {
|
||||
V0_3_4
|
||||
}
|
||||
fn compat(&self) -> &'static VersionRange {
|
||||
&*V0_3_0_COMPAT
|
||||
}
|
||||
async fn up(&self, db: PatchDb, secrets: &PgPool) -> Result<(), Error> {
|
||||
let mut account = AccountInfo::load(secrets).await?;
|
||||
let account = db
|
||||
.mutate(|d| {
|
||||
d.as_server_info_mut().as_pubkey_mut().ser(
|
||||
&ssh_key::PublicKey::from(Ed25519PublicKey::from(&account.key.ssh_key()))
|
||||
.to_openssh()?,
|
||||
)?;
|
||||
d.as_server_info_mut().as_ca_fingerprint_mut().ser(
|
||||
&account
|
||||
.root_ca_cert
|
||||
.digest(MessageDigest::sha256())
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|x| format!("{x:X}"))
|
||||
.join(":"),
|
||||
)?;
|
||||
let server_info = d.as_server_info();
|
||||
account.hostname = server_info.as_hostname().de().map(Hostname)?;
|
||||
account.server_id = server_info.as_id().de()?;
|
||||
|
||||
Ok(account)
|
||||
})
|
||||
.await?;
|
||||
account.save(secrets).await?;
|
||||
sync_hostname(&account.hostname).await?;
|
||||
|
||||
let parsed_url = Some(COMMUNITY_URL.parse().unwrap());
|
||||
db.mutate(|d| {
|
||||
let mut ui = d.as_ui().de()?;
|
||||
use imbl_value::json;
|
||||
ui["marketplace"]["known-hosts"][COMMUNITY_URL] = json!({});
|
||||
ui["marketplace"]["known-hosts"][MAIN_REGISTRY] = json!({});
|
||||
for package_id in d.as_package_data().keys()? {
|
||||
if !COMMUNITY_SERVICES.contains(&&*package_id.to_string()) {
|
||||
continue;
|
||||
}
|
||||
d.as_package_data_mut()
|
||||
.as_idx_mut(&package_id)
|
||||
.or_not_found(&package_id)?
|
||||
.as_installed_mut()
|
||||
.or_not_found(&package_id)?
|
||||
.as_marketplace_url_mut()
|
||||
.ser(&parsed_url)?;
|
||||
}
|
||||
ui["theme"] = json!("Dark".to_string());
|
||||
ui["widgets"] = json!([]);
|
||||
|
||||
d.as_ui_mut().ser(&ui)
|
||||
})
|
||||
.await
|
||||
}
|
||||
async fn down(&self, db: PatchDb, _secrets: &PgPool) -> Result<(), Error> {
|
||||
db.mutate(|d| {
|
||||
let mut ui = d.as_ui().de()?;
|
||||
let parsed_url = Some(MAIN_REGISTRY.parse().unwrap());
|
||||
for package_id in d.as_package_data().keys()? {
|
||||
if !COMMUNITY_SERVICES.contains(&&*package_id.to_string()) {
|
||||
continue;
|
||||
}
|
||||
d.as_package_data_mut()
|
||||
.as_idx_mut(&package_id)
|
||||
.or_not_found(&package_id)?
|
||||
.as_installed_mut()
|
||||
.or_not_found(&package_id)?
|
||||
.as_marketplace_url_mut()
|
||||
.ser(&parsed_url)?;
|
||||
}
|
||||
|
||||
if let imbl_value::Value::Object(ref mut obj) = ui {
|
||||
obj.remove("theme");
|
||||
obj.remove("widgets");
|
||||
}
|
||||
|
||||
ui["marketplace"]["known-hosts"][COMMUNITY_URL].take();
|
||||
ui["marketplace"]["known-hosts"][MAIN_REGISTRY].take();
|
||||
d.as_ui_mut().ser(&ui)
|
||||
})
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
use async_trait::async_trait;
|
||||
use emver::VersionRange;
|
||||
|
||||
use super::v0_3_4::V0_3_0_COMPAT;
|
||||
use super::*;
|
||||
use crate::prelude::*;
|
||||
|
||||
const V0_3_4_1: emver::Version = emver::Version::new(0, 3, 4, 1);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Version;
|
||||
|
||||
#[async_trait]
|
||||
impl VersionT for Version {
|
||||
type Previous = v0_3_4::Version;
|
||||
fn new() -> Self {
|
||||
Version
|
||||
}
|
||||
fn semver(&self) -> emver::Version {
|
||||
V0_3_4_1
|
||||
}
|
||||
fn compat(&self) -> &'static VersionRange {
|
||||
&*V0_3_0_COMPAT
|
||||
}
|
||||
async fn up(&self, _db: PatchDb, _secrets: &PgPool) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
async fn down(&self, _db: PatchDb, _secrets: &PgPool) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
use async_trait::async_trait;
|
||||
use emver::VersionRange;
|
||||
|
||||
use super::v0_3_4::V0_3_0_COMPAT;
|
||||
use super::*;
|
||||
use crate::prelude::*;
|
||||
|
||||
const V0_3_4_2: emver::Version = emver::Version::new(0, 3, 4, 2);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Version;
|
||||
|
||||
#[async_trait]
|
||||
impl VersionT for Version {
|
||||
type Previous = v0_3_4_1::Version;
|
||||
fn new() -> Self {
|
||||
Version
|
||||
}
|
||||
fn semver(&self) -> emver::Version {
|
||||
V0_3_4_2
|
||||
}
|
||||
fn compat(&self) -> &'static VersionRange {
|
||||
&*V0_3_0_COMPAT
|
||||
}
|
||||
async fn up(&self, _db: PatchDb, _secrets: &PgPool) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
async fn down(&self, _db: PatchDb, _secrets: &PgPool) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
use async_trait::async_trait;
|
||||
use emver::VersionRange;
|
||||
|
||||
use super::v0_3_4::V0_3_0_COMPAT;
|
||||
use super::*;
|
||||
use crate::prelude::*;
|
||||
|
||||
const V0_3_4_3: emver::Version = emver::Version::new(0, 3, 4, 3);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Version;
|
||||
|
||||
#[async_trait]
|
||||
impl VersionT for Version {
|
||||
type Previous = v0_3_4_2::Version;
|
||||
fn new() -> Self {
|
||||
Version
|
||||
}
|
||||
fn semver(&self) -> emver::Version {
|
||||
V0_3_4_3
|
||||
}
|
||||
fn compat(&self) -> &'static VersionRange {
|
||||
&V0_3_0_COMPAT
|
||||
}
|
||||
async fn up(&self, _db: PatchDb, _secrets: &PgPool) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
async fn down(&self, _db: PatchDb, _secrets: &PgPool) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
use async_trait::async_trait;
|
||||
use emver::VersionRange;
|
||||
use models::ResultExt;
|
||||
use sqlx::PgPool;
|
||||
|
||||
use super::v0_3_4::V0_3_0_COMPAT;
|
||||
use super::{v0_3_4_3, VersionT};
|
||||
use crate::prelude::*;
|
||||
|
||||
const V0_3_4_4: emver::Version = emver::Version::new(0, 3, 4, 4);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Version;
|
||||
|
||||
#[async_trait]
|
||||
impl VersionT for Version {
|
||||
type Previous = v0_3_4_3::Version;
|
||||
fn new() -> Self {
|
||||
Version
|
||||
}
|
||||
fn semver(&self) -> emver::Version {
|
||||
V0_3_4_4
|
||||
}
|
||||
fn compat(&self) -> &'static VersionRange {
|
||||
&V0_3_0_COMPAT
|
||||
}
|
||||
async fn up(&self, db: PatchDb, _secrets: &PgPool) -> Result<(), Error> {
|
||||
db.mutate(|v| {
|
||||
let tor_address_lens = v.as_server_info_mut().as_tor_address_mut();
|
||||
let mut tor_addr = tor_address_lens.de()?;
|
||||
tor_addr
|
||||
.set_scheme("https")
|
||||
.map_err(|_| eyre!("unable to update url scheme to https"))
|
||||
.with_kind(crate::ErrorKind::ParseUrl)?;
|
||||
tor_address_lens.ser(&tor_addr)
|
||||
})
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
async fn down(&self, _db: PatchDb, _secrets: &PgPool) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
use async_trait::async_trait;
|
||||
use emver::VersionRange;
|
||||
use lazy_static::lazy_static;
|
||||
use sqlx::PgPool;
|
||||
|
||||
use super::*;
|
||||
use super::v0_3_4::V0_3_0_COMPAT;
|
||||
use super::VersionT;
|
||||
use crate::prelude::*;
|
||||
|
||||
const V0_3_5: emver::Version = emver::Version::new(0, 3, 5, 0);
|
||||
lazy_static! {
|
||||
static ref V0_3_0_COMPAT: VersionRange = VersionRange::Conj(
|
||||
Box::new(VersionRange::Anchor(
|
||||
@@ -15,6 +15,7 @@ lazy_static! {
|
||||
Box::new(VersionRange::Anchor(emver::LTE, Current::new().semver())),
|
||||
);
|
||||
}
|
||||
const V0_3_5_1: emver::Version = emver::Version::new(0, 3, 5, 1);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Version;
|
||||
@@ -26,15 +27,15 @@ impl VersionT for Version {
|
||||
Version
|
||||
}
|
||||
fn semver(&self) -> emver::Version {
|
||||
V0_3_5
|
||||
V0_3_5_1
|
||||
}
|
||||
fn compat(&self) -> &'static VersionRange {
|
||||
&V0_3_0_COMPAT
|
||||
}
|
||||
async fn up(&self, _db: &PatchDb, _secrets: &PgPool) -> Result<(), Error> {
|
||||
async fn up(&self, _db: PatchDb, _secrets: &PgPool) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
async fn down(&self, _db: &PatchDb, _secrets: &PgPool) -> Result<(), Error> {
|
||||
async fn down(&self, _db: PatchDb, _secrets: &PgPool) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user