1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 09:04:12 +02:00

clippy fixes

This commit is contained in:
Robin Appelman 2023-05-04 18:53:38 +02:00
commit abe04b52d0
12 changed files with 101 additions and 104 deletions

View file

@ -21,7 +21,7 @@
# `nix develop` # `nix develop`
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
nativeBuildInputs = with pkgs; [ rustc cargo bacon cargo-edit cargo-outdated ]; nativeBuildInputs = with pkgs; [ rustc cargo bacon cargo-edit cargo-outdated clippy ];
}; };
} }
) // { ) // {

View file

@ -82,7 +82,7 @@ impl CloudOptions {
#[test] #[test]
fn test_option_parse() { fn test_option_parse() {
use crate::service::{LDAPAdmin, LDAP}; use crate::service::{Ldap, LdapAdmin};
let mut args = vec![].into_iter().peekable(); let mut args = vec![].into_iter().peekable();
assert_eq!( assert_eq!(
@ -127,7 +127,7 @@ fn test_option_parse() {
CloudOptions { CloudOptions {
php: PhpVersion::Php74, php: PhpVersion::Php74,
db: Database::Postgres, db: Database::Postgres,
services: vec![Service::LDAP(LDAP), Service::LDAPAdmin(LDAPAdmin)], services: vec![Service::Ldap(Ldap), Service::LdapAdmin(LdapAdmin)],
..Default::default() ..Default::default()
} }
); );
@ -137,7 +137,7 @@ fn test_option_parse() {
CloudOptions { CloudOptions {
php: PhpVersion::Php74, php: PhpVersion::Php74,
db: Database::Postgres, db: Database::Postgres,
services: vec![Service::LDAP(LDAP), Service::LDAPAdmin(LDAPAdmin)], services: vec![Service::Ldap(Ldap), Service::LdapAdmin(LdapAdmin)],
..Default::default() ..Default::default()
} }
); );
@ -159,7 +159,7 @@ pub struct Cloud {
impl Cloud { impl Cloud {
pub async fn create( pub async fn create(
docker: &mut Docker, docker: &Docker,
options: CloudOptions, options: CloudOptions,
config: &HazeConfig, config: &HazeConfig,
) -> Result<Self> { ) -> Result<Self> {
@ -227,7 +227,7 @@ impl Cloud {
.await .await
.into_diagnostic()? .into_diagnostic()?
.id .id
.ok_or(Report::msg("No network id in response")) .ok_or_else(|| Report::msg("No network id in response"))
.wrap_err("Failed to create network")?; .wrap_err("Failed to create network")?;
let network_info = docker let network_info = docker
@ -237,15 +237,15 @@ impl Cloud {
let gateway = network_info let gateway = network_info
.ipam .ipam
.as_ref() .as_ref()
.ok_or(Report::msg("Network has no ip info"))? .ok_or_else(|| Report::msg("Network has no ip info"))?
.config .config
.as_deref() .as_deref()
.ok_or(Report::msg("Network has no ip info"))? .ok_or_else(|| Report::msg("Network has no ip info"))?
.first() .first()
.ok_or(Report::msg("Network has no ip info"))? .ok_or_else(|| Report::msg("Network has no ip info"))?
.gateway .gateway
.as_deref() .as_deref()
.ok_or(Report::msg("Network has no ip info"))?; .ok_or_else(|| Report::msg("Network has no ip info"))?;
let mut containers = Vec::new(); let mut containers = Vec::new();
@ -343,7 +343,7 @@ impl Cloud {
.networks .networks
.unwrap() .unwrap()
.iter() .iter()
.filter_map(|(name, network)| name.eq("haze").then(|| network)) .filter_map(|(name, network)| name.eq("haze").then_some(network))
.next() .next()
.unwrap() .unwrap()
.ip_address .ip_address
@ -404,7 +404,7 @@ impl Cloud {
}) })
} }
pub async fn destroy(self, docker: &mut Docker) -> Result<()> { pub async fn destroy(self, docker: &Docker) -> Result<()> {
for container in self.containers { for container in self.containers {
docker docker
.remove_container( .remove_container(
@ -438,7 +438,7 @@ impl Cloud {
pub async fn exec<S: Into<String>>( pub async fn exec<S: Into<String>>(
&self, &self,
docker: &mut Docker, docker: &Docker,
cmd: Vec<S>, cmd: Vec<S>,
tty: bool, tty: bool,
) -> Result<ExitCode> { ) -> Result<ExitCode> {
@ -575,10 +575,10 @@ impl Cloud {
.await? .await?
.into_iter() .into_iter()
.next() .next()
.ok_or(Report::msg("No clouds running matching filter")) .ok_or_else(|| Report::msg("No clouds running matching filter"))
} }
pub async fn wait_for_start(&self, docker: &mut Docker) -> Result<()> { pub async fn wait_for_start(&self, docker: &Docker) -> Result<()> {
self.php self.php
.wait_for_start(self.ip) .wait_for_start(self.ip)
.await .await
@ -597,7 +597,7 @@ impl Cloud {
Ok(()) Ok(())
} }
pub async fn enable_app<S: Into<String>>(&self, docker: &mut Docker, app: S) -> Result<()> { pub async fn enable_app<S: Into<String>>(&self, docker: &Docker, app: S) -> Result<()> {
self.exec( self.exec(
docker, docker,
vec![ vec![
@ -612,7 +612,7 @@ impl Cloud {
Ok(()) Ok(())
} }
pub async fn pin(&self, docker: &mut Docker) -> Result<()> { pub async fn pin(&self, docker: &Docker) -> Result<()> {
// abuse memory limits as editable label // abuse memory limits as editable label
docker docker
.update_container( .update_container(
@ -626,7 +626,7 @@ impl Cloud {
.into_diagnostic() .into_diagnostic()
} }
pub async fn unpin(&self, docker: &mut Docker) -> Result<()> { pub async fn unpin(&self, docker: &Docker) -> Result<()> {
// abuse memory limits as editable label // abuse memory limits as editable label
docker docker
.update_container( .update_container(

View file

@ -164,7 +164,7 @@ pub struct ProxyConfig {
impl ProxyConfig { impl ProxyConfig {
/// Get a public address for a service, either with direct ip or through the proxy /// Get a public address for a service, either with direct ip or through the proxy
pub fn addr(&self, id: &str, ip: IpAddr) -> String { pub fn addr(&self, id: &str, ip: IpAddr) -> String {
let clean_id = id.strip_prefix("haze-").unwrap_or(&id); let clean_id = id.strip_prefix("haze-").unwrap_or(id);
match (&self.address, self.https) { match (&self.address, self.https) {
(public, true) if !public.is_empty() => format!("https://{clean_id}.{public}"), (public, true) if !public.is_empty() => format!("https://{clean_id}.{public}"),
(public, false) if !public.is_empty() => format!("http://{clean_id}.{public}"), (public, false) if !public.is_empty() => format!("http://{clean_id}.{public}"),
@ -173,7 +173,7 @@ impl ProxyConfig {
} }
pub fn addr_with_port(&self, id: &str, ip: IpAddr, port: u16) -> String { pub fn addr_with_port(&self, id: &str, ip: IpAddr, port: u16) -> String {
let clean_id = id.strip_prefix("haze-").unwrap_or(&id); let clean_id = id.strip_prefix("haze-").unwrap_or(id);
match (&self.address, self.https) { match (&self.address, self.https) {
(public, true) if !public.is_empty() => format!("https://{clean_id}.{public}"), (public, true) if !public.is_empty() => format!("https://{clean_id}.{public}"),
(public, false) if !public.is_empty() => format!("http://{clean_id}.{public}"), (public, false) if !public.is_empty() => format!("http://{clean_id}.{public}"),

View file

@ -179,7 +179,7 @@ impl Database {
pub async fn spawn( pub async fn spawn(
&self, &self,
docker: &mut Docker, docker: &Docker,
cloud_id: &str, cloud_id: &str,
network: &str, network: &str,
) -> Result<Option<String>> { ) -> Result<Option<String>> {
@ -242,14 +242,14 @@ impl Database {
pub async fn exec_sh<S: Into<String>>( pub async fn exec_sh<S: Into<String>>(
&self, &self,
docker: &mut Docker, docker: &Docker,
cloud_id: &str, cloud_id: &str,
cmd: Vec<S>, cmd: Vec<S>,
tty: bool, tty: bool,
) -> Result<ExitCode> { ) -> Result<ExitCode> {
let container = match self.family() { let container = match self.family() {
DatabaseFamily::Sqlite => cloud_id.to_string(), DatabaseFamily::Sqlite => cloud_id.to_string(),
_ => format!("{}-db", cloud_id.to_string()), _ => format!("{}-db", cloud_id),
}; };
if tty { if tty {
exec_tty(docker, &container, "root", cmd, vec![]).await exec_tty(docker, &container, "root", cmd, vec![]).await
@ -258,7 +258,7 @@ impl Database {
} }
} }
pub async fn exec(&self, docker: &mut Docker, cloud_id: &str, root: bool) -> Result<ExitCode> { pub async fn exec(&self, docker: &Docker, cloud_id: &str, root: bool) -> Result<ExitCode> {
match self.family() { match self.family() {
DatabaseFamily::Sqlite => { DatabaseFamily::Sqlite => {
exec_tty( exec_tty(
@ -309,7 +309,7 @@ impl Database {
} }
} }
pub async fn wait_for_start(&self, docker: &mut Docker, cloud_id: &str) -> Result<()> { pub async fn wait_for_start(&self, docker: &Docker, cloud_id: &str) -> Result<()> {
let time = if self.family() == DatabaseFamily::Oracle { let time = if self.family() == DatabaseFamily::Oracle {
45 45
} else { } else {
@ -327,9 +327,9 @@ impl Database {
.wrap_err(format!("Timeout after {time} seconds"))? .wrap_err(format!("Timeout after {time} seconds"))?
} }
pub async fn ip(&self, docker: &mut Docker, cloud_id: &str) -> Option<IpAddr> { pub async fn ip(&self, docker: &Docker, cloud_id: &str) -> Option<IpAddr> {
match self.family() { match self.family() {
DatabaseFamily::Sqlite => return None, DatabaseFamily::Sqlite => None,
_ => docker _ => docker
.inspect_container(&format!("{}-db", cloud_id), None) .inspect_container(&format!("{}-db", cloud_id), None)
.await .await
@ -345,7 +345,7 @@ impl Database {
} }
} }
async fn is_healthy(&self, docker: &mut Docker, cloud_id: &str) -> Result<bool> { async fn is_healthy(&self, docker: &Docker, cloud_id: &str) -> Result<bool> {
match self.family() { match self.family() {
DatabaseFamily::Sqlite => Ok(true), DatabaseFamily::Sqlite => Ok(true),
DatabaseFamily::Mysql | DatabaseFamily::MariaDB => { DatabaseFamily::Mysql | DatabaseFamily::MariaDB => {

View file

@ -12,7 +12,7 @@ use tokio::task::spawn;
use tokio::time::sleep; use tokio::time::sleep;
pub async fn exec_tty<S1: AsRef<str>, S2: Into<String>>( pub async fn exec_tty<S1: AsRef<str>, S2: Into<String>>(
docker: &mut Docker, docker: &Docker,
container: S1, container: S1,
user: &str, user: &str,
cmd: Vec<S2>, cmd: Vec<S2>,

View file

@ -11,11 +11,11 @@ pub fn checkout_all<P: AsRef<Path>>(sources_root: P, branch: &str) -> Result<()>
let app = app.into_diagnostic()?; let app = app.into_diagnostic()?;
if app.metadata().into_diagnostic()?.is_dir() { if app.metadata().into_diagnostic()?.is_dir() {
let app_dir = app.path(); let app_dir = app.path();
if has_branch(&app_dir, &branch).unwrap_or_default() if has_branch(&app_dir, branch).unwrap_or_default()
&& get_branch(&app_dir).unwrap_or_default().trim() != branch && get_branch(&app_dir).unwrap_or_default().trim() != branch
{ {
print!("{}", app.file_name().to_string_lossy()); print!("{}", app.file_name().to_string_lossy());
if let Err(e) = checkout(&app_dir, &branch) { if let Err(e) = checkout(&app_dir, branch) {
println!(": {}", e); println!(": {}", e);
} else { } else {
println!(""); println!("");
@ -39,7 +39,7 @@ fn has_branch<P: AsRef<Path>>(repo: P, branch: &str) -> Result<bool> {
error!(stdout = stdout, stderr = stderr, "git command failed"); error!(stdout = stdout, stderr = stderr, "git command failed");
} }
for line in stdout.split("\n") { for line in stdout.split('\n') {
let line = line.trim(); let line = line.trim();
if line == branch { if line == branch {
return Ok(true); return Ok(true);

View file

@ -13,12 +13,12 @@ pub async fn image_exists(docker: &Docker, image: &str) -> bool {
} }
pub async fn pull_image(docker: &Docker, image: &str) -> Result<()> { pub async fn pull_image(docker: &Docker, image: &str) -> Result<()> {
if let Err(_) = docker.inspect_image(image).await { if docker.inspect_image(image).await.is_err() {
println!("Pulling image {}", image); println!("Pulling image {}", image);
let mut info_stream = docker.create_image( let mut info_stream = docker.create_image(
Some(CreateImageOptions { Some(CreateImageOptions {
from_image: if image.contains(":") { from_image: if image.contains(':') {
image.to_string() image.to_string()
} else { } else {
format!("{}:latest", image) format!("{}:latest", image)

View file

@ -34,7 +34,7 @@ async fn main() -> Result<()> {
miette::set_panic_hook(); miette::set_panic_hook();
tracing_subscriber::fmt::init(); tracing_subscriber::fmt::init();
let mut docker = Docker::connect_with_local_defaults() let docker = Docker::connect_with_local_defaults()
.into_diagnostic() .into_diagnostic()
.wrap_err("Failed to connect to docker")?; .wrap_err("Failed to connect to docker")?;
let config = HazeConfig::load().wrap_err("Failed to load config")?; let config = HazeConfig::load().wrap_err("Failed to load config")?;
@ -43,16 +43,16 @@ async fn main() -> Result<()> {
match args { match args {
HazeArgs::Clean => { HazeArgs::Clean => {
let list = Cloud::list(&mut docker, None, &config).await?; let list = Cloud::list(&docker, None, &config).await?;
for cloud in list.into_iter().filter(|cloud| !cloud.pinned) { for cloud in list.into_iter().filter(|cloud| !cloud.pinned) {
if let Err(e) = cloud.destroy(&mut docker).await { if let Err(e) = cloud.destroy(&docker).await {
eprintln!("Error while removing cloud: {:#}", e); eprintln!("Error while removing cloud: {:#}", e);
} }
} }
clear_networks(&docker).await?; clear_networks(&docker).await?;
} }
HazeArgs::List { filter } => { HazeArgs::List { filter } => {
let list = Cloud::list(&mut docker, filter, &config).await?; let list = Cloud::list(&docker, filter, &config).await?;
for cloud in list { for cloud in list {
let mut services: Vec<_> = cloud.services.iter().map(Service::name).collect(); let mut services: Vec<_> = cloud.services.iter().map(Service::name).collect();
services.push(cloud.db.name()); services.push(cloud.db.name());
@ -69,11 +69,11 @@ async fn main() -> Result<()> {
} }
} }
HazeArgs::Start { options } => { HazeArgs::Start { options } => {
setup(&mut docker, options, &config).await?; setup(&docker, options, &config).await?;
} }
HazeArgs::Stop { filter } => { HazeArgs::Stop { filter } => {
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?; let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
cloud.destroy(&mut docker).await?; cloud.destroy(&docker).await?;
} }
HazeArgs::Logs { HazeArgs::Logs {
filter, filter,
@ -81,7 +81,7 @@ async fn main() -> Result<()> {
count, count,
service, service,
} => { } => {
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?; let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
let container = if let Some(service) = service { let container = if let Some(service) = service {
service.container_name(&cloud.id) service.container_name(&cloud.id)
} else { } else {
@ -94,12 +94,12 @@ async fn main() -> Result<()> {
service, service,
command, command,
} => { } => {
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?; let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
match service { match service {
None => { None => {
cloud cloud
.exec( .exec(
&mut docker, &docker,
if command.is_empty() { if command.is_empty() {
vec!["bash".to_string()] vec!["bash".to_string()]
} else { } else {
@ -113,7 +113,7 @@ async fn main() -> Result<()> {
cloud cloud
.db .db
.exec_sh( .exec_sh(
&mut docker, &docker,
&cloud.id, &cloud.id,
if command.is_empty() { if command.is_empty() {
vec!["bash".to_string()] vec!["bash".to_string()]
@ -130,31 +130,31 @@ async fn main() -> Result<()> {
filter, filter,
mut command, mut command,
} => { } => {
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?; let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
command.insert(0, "occ".to_string()); command.insert(0, "occ".to_string());
cloud cloud
.exec(&mut docker, command, atty::is(atty::Stream::Stdout)) .exec(&docker, command, atty::is(atty::Stream::Stdout))
.await?; .await?;
} }
HazeArgs::Db { filter, root } => { HazeArgs::Db { filter, root } => {
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?; let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
cloud.db.exec(&mut docker, &cloud.id, root).await?; cloud.db.exec(&docker, &cloud.id, root).await?;
} }
HazeArgs::Open { filter } => { HazeArgs::Open { filter } => {
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?; let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
match cloud.ip { match cloud.ip {
Some(_) => opener::open(cloud.address).into_diagnostic()?, Some(_) => opener::open(cloud.address).into_diagnostic()?,
None => eprintln!("{} is not running", cloud.id), None => eprintln!("{} is not running", cloud.id),
} }
} }
HazeArgs::Test { options, mut args } => { HazeArgs::Test { options, mut args } => {
let cloud = Cloud::create(&mut docker, options, &config).await?; let cloud = Cloud::create(&docker, options, &config).await?;
println!("Waiting for servers to start"); println!("Waiting for servers to start");
cloud.wait_for_start(&mut docker).await?; cloud.wait_for_start(&docker).await?;
println!("Installing"); println!("Installing");
if let Err(e) = cloud if let Err(e) = cloud
.exec( .exec(
&mut docker, &docker,
vec![ vec![
"install", "install",
&config.auto_setup.username, &config.auto_setup.username,
@ -164,7 +164,7 @@ async fn main() -> Result<()> {
) )
.await .await
{ {
cloud.destroy(&mut docker).await?; cloud.destroy(&docker).await?;
return Err(e); return Err(e);
} }
if let Some(app) = args if let Some(app) = args
@ -174,23 +174,23 @@ async fn main() -> Result<()> {
.map(|path| &path[0..path.find('/').unwrap_or(path.len())]) .map(|path| &path[0..path.find('/').unwrap_or(path.len())])
{ {
if app.starts_with("files_") { if app.starts_with("files_") {
cloud.enable_app(&mut docker, "files_external").await?; cloud.enable_app(&docker, "files_external").await?;
} }
println!("Enabling {}", app); println!("Enabling {}", app);
cloud.enable_app(&mut docker, app).await?; cloud.enable_app(&docker, app).await?;
} }
args.insert(0, "tests".to_string()); args.insert(0, "tests".to_string());
cloud.exec(&mut docker, args, false).await?; cloud.exec(&docker, args, false).await?;
cloud.destroy(&mut docker).await?; cloud.destroy(&docker).await?;
} }
HazeArgs::Integration { options, mut args } => { HazeArgs::Integration { options, mut args } => {
let cloud = Cloud::create(&mut docker, options, &config).await?; let cloud = Cloud::create(&docker, options, &config).await?;
println!("Waiting for servers to start"); println!("Waiting for servers to start");
cloud.wait_for_start(&mut docker).await?; cloud.wait_for_start(&docker).await?;
println!("Installing"); println!("Installing");
if let Err(e) = cloud if let Err(e) = cloud
.exec( .exec(
&mut docker, &docker,
vec![ vec![
"install", "install",
&config.auto_setup.username, &config.auto_setup.username,
@ -200,49 +200,45 @@ async fn main() -> Result<()> {
) )
.await .await
{ {
cloud.destroy(&mut docker).await?; cloud.destroy(&docker).await?;
return Err(e); return Err(e);
} }
args.insert(0, "integration".to_string()); args.insert(0, "integration".to_string());
cloud.exec(&mut docker, args, false).await?; cloud.exec(&docker, args, false).await?;
cloud.destroy(&mut docker).await?; cloud.destroy(&docker).await?;
} }
HazeArgs::Fmt { path } => { HazeArgs::Fmt { path } => {
let cloud = Cloud::create(&mut docker, CloudOptions::default(), &config).await?; let cloud = Cloud::create(&docker, CloudOptions::default(), &config).await?;
let mut out_buffer = Vec::<u8>::with_capacity(1024); let mut out_buffer = Vec::<u8>::with_capacity(1024);
println!("Waiting for servers to start"); println!("Waiting for servers to start");
cloud.wait_for_start(&mut docker).await?; cloud.wait_for_start(&docker).await?;
println!("Installing composer"); println!("Installing composer");
if let Err(e) = cloud if let Err(e) = cloud
.exec_with_output( .exec_with_output(&docker, vec!["composer", "install"], Some(&mut out_buffer))
&mut docker,
vec!["composer", "install"],
Some(&mut out_buffer),
)
.await .await
.and_then(|c| c.to_result()) .and_then(|c| c.to_result())
{ {
eprintln!("{}", String::from_utf8_lossy(&out_buffer)); eprintln!("{}", String::from_utf8_lossy(&out_buffer));
cloud.destroy(&mut docker).await?; cloud.destroy(&docker).await?;
return Err(e); return Err(e);
} }
out_buffer.clear(); out_buffer.clear();
println!("Formatting"); println!("Formatting");
if let Err(e) = cloud if let Err(e) = cloud
.exec( .exec(
&mut docker, &docker,
vec!["composer", "run", "cs:fix", path.as_str()], vec!["composer", "run", "cs:fix", path.as_str()],
false, false,
) )
.await .await
{ {
cloud.destroy(&mut docker).await?; cloud.destroy(&docker).await?;
return Err(e); return Err(e);
} }
println!("Cleanup"); println!("Cleanup");
if let Err(e) = cloud if let Err(e) = cloud
.exec_with_output( .exec_with_output(
&mut docker, &docker,
vec!["git", "clean", "-fd", "lib/composer"], vec!["git", "clean", "-fd", "lib/composer"],
Some(&mut out_buffer), Some(&mut out_buffer),
) )
@ -250,12 +246,12 @@ async fn main() -> Result<()> {
.and_then(|c| c.to_result()) .and_then(|c| c.to_result())
{ {
eprintln!("{}", String::from_utf8_lossy(&out_buffer)); eprintln!("{}", String::from_utf8_lossy(&out_buffer));
cloud.destroy(&mut docker).await?; cloud.destroy(&docker).await?;
return Err(e); return Err(e);
} }
if let Err(e) = cloud if let Err(e) = cloud
.exec_with_output( .exec_with_output(
&mut docker, &docker,
vec!["git", "checkout", "lib/composer"], vec!["git", "checkout", "lib/composer"],
Some(&mut out_buffer), Some(&mut out_buffer),
) )
@ -263,16 +259,16 @@ async fn main() -> Result<()> {
.and_then(|c| c.to_result()) .and_then(|c| c.to_result())
{ {
eprintln!("{}", String::from_utf8_lossy(&out_buffer)); eprintln!("{}", String::from_utf8_lossy(&out_buffer));
cloud.destroy(&mut docker).await?; cloud.destroy(&docker).await?;
return Err(e); return Err(e);
} }
cloud.destroy(&mut docker).await?; cloud.destroy(&docker).await?;
} }
HazeArgs::Shell { command, options } => { HazeArgs::Shell { command, options } => {
let cloud = setup(&mut docker, options, &config).await?; let cloud = setup(&docker, options, &config).await?;
cloud cloud
.exec( .exec(
&mut docker, &docker,
if command.is_empty() { if command.is_empty() {
vec!["bash".to_string()] vec!["bash".to_string()]
} else { } else {
@ -281,15 +277,15 @@ async fn main() -> Result<()> {
true, true,
) )
.await?; .await?;
cloud.destroy(&mut docker).await?; cloud.destroy(&docker).await?;
} }
HazeArgs::Pin { filter } => { HazeArgs::Pin { filter } => {
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?; let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
cloud.pin(&mut docker).await?; cloud.pin(&docker).await?;
} }
HazeArgs::Unpin { filter } => { HazeArgs::Unpin { filter } => {
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?; let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
cloud.unpin(&mut docker).await?; cloud.unpin(&docker).await?;
} }
HazeArgs::Proxy => { HazeArgs::Proxy => {
proxy(docker, config).await?; proxy(docker, config).await?;
@ -302,7 +298,7 @@ async fn main() -> Result<()> {
command, command,
args, args,
} => { } => {
let cloud = Cloud::get_by_filter(&mut docker, filter, &config).await?; let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
let ip = cloud let ip = cloud
.ip .ip
.ok_or_else(|| Report::msg(format!("{} is not running", cloud.id)))?; .ok_or_else(|| Report::msg(format!("{} is not running", cloud.id)))?;
@ -318,7 +314,7 @@ async fn main() -> Result<()> {
}; };
let db_ip = cloud let db_ip = cloud
.db .db
.ip(&mut docker, &cloud.id) .ip(&docker, &cloud.id)
.await .await
.ok_or_else(|| Report::msg(format!("{}-db is not running", cloud.id)))?; .ok_or_else(|| Report::msg(format!("{}-db is not running", cloud.id)))?;
@ -338,8 +334,8 @@ async fn main() -> Result<()> {
Ok(()) Ok(())
} }
async fn setup(docker: &mut Docker, options: CloudOptions, config: &HazeConfig) -> Result<Cloud> { async fn setup(docker: &Docker, options: CloudOptions, config: &HazeConfig) -> Result<Cloud> {
let cloud = Cloud::create(docker, options, &config).await?; let cloud = Cloud::create(docker, options, config).await?;
println!("{}", cloud.address); println!("{}", cloud.address);
let host = cloud.address.split_once("://").expect("no address?").1; let host = cloud.address.split_once("://").expect("no address?").1;
if config.auto_setup.enabled { if config.auto_setup.enabled {
@ -415,7 +411,7 @@ async fn setup(docker: &mut Docker, options: CloudOptions, config: &HazeConfig)
} }
} }
for service in &cloud.services { for service in &cloud.services {
for cmd in service.post_setup(&docker, &cloud.id, config).await? { for cmd in service.post_setup(docker, &cloud.id, config).await? {
cloud cloud
.exec(docker, shell_words::split(&cmd).into_diagnostic()?, false) .exec(docker, shell_words::split(&cmd).into_diagnostic()?, false)
.await?; .await?;
@ -423,7 +419,7 @@ async fn setup(docker: &mut Docker, options: CloudOptions, config: &HazeConfig)
} }
for cmd in &config.auto_setup.post_setup { for cmd in &config.auto_setup.post_setup {
cloud cloud
.exec(docker, shell_words::split(&cmd).into_diagnostic()?, false) .exec(docker, shell_words::split(cmd).into_diagnostic()?, false)
.await?; .await?;
} }
} }

View file

@ -86,9 +86,10 @@ impl PhpVersion {
} }
} }
#[allow(clippy::too_many_arguments)]
pub async fn spawn( pub async fn spawn(
&self, &self,
docker: &mut Docker, docker: &Docker,
id: &str, id: &str,
env: Vec<String>, env: Vec<String>,
db: &Database, db: &Database,
@ -170,11 +171,11 @@ impl PhpVersion {
let client = Client::new(); let client = Client::new();
let url = Url::parse(&format!( let url = Url::parse(&format!(
"http://{}/status.php", "http://{}/status.php",
ip.ok_or(Report::msg("Container not running"))? ip.ok_or_else(|| Report::msg("Container not running"))?
)) ))
.into_diagnostic()?; .into_diagnostic()?;
timeout(Duration::from_secs(15), async { timeout(Duration::from_secs(15), async {
while !client.get(url.clone()).send().await.is_ok() { while client.get(url.clone()).send().await.is_err() {
sleep(Duration::from_millis(100)).await sleep(Duration::from_millis(100)).await
} }
}) })

View file

@ -91,7 +91,7 @@ impl ActiveInstances {
} }
pub fn last(&self) -> Option<SocketAddr> { pub fn last(&self) -> Option<SocketAddr> {
self.last.lock().unwrap().clone() *self.last.lock().unwrap()
} }
async fn update_last(&self) { async fn update_last(&self) {

View file

@ -10,7 +10,7 @@ mod smb;
use crate::config::HazeConfig; use crate::config::HazeConfig;
pub use crate::service::clam::ClamIcap; pub use crate::service::clam::ClamIcap;
use crate::service::kaspersky::{Kaspersky, KasperskyIcap}; use crate::service::kaspersky::{Kaspersky, KasperskyIcap};
pub use crate::service::ldap::{LDAPAdmin, LDAP}; pub use crate::service::ldap::{Ldap, LdapAdmin};
pub use crate::service::objectstore::ObjectStore; pub use crate::service::objectstore::ObjectStore;
pub use crate::service::office::Office; pub use crate::service::office::Office;
pub use crate::service::onlyoffice::OnlyOffice; pub use crate::service::onlyoffice::OnlyOffice;
@ -143,8 +143,8 @@ pub trait ServiceTrait {
#[derive(Clone, Eq, PartialEq, Debug)] #[derive(Clone, Eq, PartialEq, Debug)]
pub enum Service { pub enum Service {
ObjectStore(ObjectStore), ObjectStore(ObjectStore),
LDAP(LDAP), Ldap(Ldap),
LDAPAdmin(LDAPAdmin), LdapAdmin(LdapAdmin),
OnlyOffice(OnlyOffice), OnlyOffice(OnlyOffice),
Office(Office), Office(Office),
Push(NotifyPush), Push(NotifyPush),
@ -161,7 +161,7 @@ impl Service {
"s3m" => Some(&[Service::ObjectStore(ObjectStore::S3m)]), "s3m" => Some(&[Service::ObjectStore(ObjectStore::S3m)]),
"s3mb" => Some(&[Service::ObjectStore(ObjectStore::S3mb)]), "s3mb" => Some(&[Service::ObjectStore(ObjectStore::S3mb)]),
"azure" => Some(&[Service::ObjectStore(ObjectStore::Azure)]), "azure" => Some(&[Service::ObjectStore(ObjectStore::Azure)]),
"ldap" => Some(&[Service::LDAP(LDAP), Service::LDAPAdmin(LDAPAdmin)]), "ldap" => Some(&[Service::Ldap(Ldap), Service::LdapAdmin(LdapAdmin)]),
"onlyoffice" => Some(&[Service::OnlyOffice(OnlyOffice)]), "onlyoffice" => Some(&[Service::OnlyOffice(OnlyOffice)]),
"office" => Some(&[Service::Office(Office)]), "office" => Some(&[Service::Office(Office)]),
"push" => Some(&[Service::Push(NotifyPush)]), "push" => Some(&[Service::Push(NotifyPush)]),

View file

@ -9,10 +9,10 @@ use maplit::hashmap;
use miette::{IntoDiagnostic, Report}; use miette::{IntoDiagnostic, Report};
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq)]
pub struct LDAP; pub struct Ldap;
#[async_trait::async_trait] #[async_trait::async_trait]
impl ServiceTrait for LDAP { impl ServiceTrait for Ldap {
fn name(&self) -> &str { fn name(&self) -> &str {
"ldap" "ldap"
} }
@ -78,10 +78,10 @@ impl ServiceTrait for LDAP {
} }
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq)]
pub struct LDAPAdmin; pub struct LdapAdmin;
#[async_trait::async_trait] #[async_trait::async_trait]
impl ServiceTrait for LDAPAdmin { impl ServiceTrait for LdapAdmin {
fn name(&self) -> &str { fn name(&self) -> &str {
"ldap-admin" "ldap-admin"
} }