Feature/callbacks (#2678)

* wip

* initialize callbacks

* wip

* smtp

* list_service_interfaces

* wip

* wip

* fix domains

* fix hostname handling in NetService

* misc fixes

* getInstalledPackages

* misc fixes

* publish v6 lib

* refactor service effects

* fix import

* fix container runtime

* fix tests

* apply suggestions from review
This commit is contained in:
Aiden McClelland
2024-07-25 11:44:51 -06:00
committed by GitHub
parent ab465a755e
commit b36b62c68e
113 changed files with 4853 additions and 2517 deletions

View File

@@ -1,3 +1,5 @@
use imbl_value::InternedString;
use lazy_format::lazy_format;
use rand::{thread_rng, Rng};
use tokio::process::Command;
use tracing::instrument;
@@ -5,7 +7,7 @@ use tracing::instrument;
use crate::util::Invoke;
use crate::{Error, ErrorKind};
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct Hostname(pub String);
pub struct Hostname(pub InternedString);
lazy_static::lazy_static! {
static ref ADJECTIVES: Vec<String> = include_str!("./assets/adjectives.txt").lines().map(|x| x.to_string()).collect();
@@ -18,15 +20,16 @@ impl AsRef<str> for Hostname {
}
impl Hostname {
pub fn lan_address(&self) -> String {
format!("https://{}.local", self.0)
pub fn lan_address(&self) -> InternedString {
InternedString::from_display(&lazy_format!("https://{}.local", self.0))
}
pub fn local_domain_name(&self) -> String {
format!("{}.local", self.0)
pub fn local_domain_name(&self) -> InternedString {
InternedString::from_display(&lazy_format!("{}.local", self.0))
}
pub fn no_dot_host_name(&self) -> String {
self.0.to_owned()
pub fn no_dot_host_name(&self) -> InternedString {
self.0.clone()
}
}
@@ -34,7 +37,9 @@ pub fn generate_hostname() -> Hostname {
let mut rng = thread_rng();
let adjective = &ADJECTIVES[rng.gen_range(0..ADJECTIVES.len())];
let noun = &NOUNS[rng.gen_range(0..NOUNS.len())];
Hostname(format!("{adjective}-{noun}"))
Hostname(InternedString::from_display(&lazy_format!(
"{adjective}-{noun}"
)))
}
pub fn generate_id() -> String {
@@ -48,12 +53,12 @@ pub async fn get_current_hostname() -> Result<Hostname, Error> {
.invoke(ErrorKind::ParseSysInfo)
.await?;
let out_string = String::from_utf8(out)?;
Ok(Hostname(out_string.trim().to_owned()))
Ok(Hostname(out_string.trim().into()))
}
#[instrument(skip_all)]
pub async fn set_hostname(hostname: &Hostname) -> Result<(), Error> {
let hostname: &String = &hostname.0;
let hostname = &*hostname.0;
Command::new("hostnamectl")
.arg("--static")
.arg("set-hostname")