diff --git a/src/symbols/acme/mod.rs b/src/symbols/acme/mod.rs index c6390ef..556ec82 100644 --- a/src/symbols/acme/mod.rs +++ b/src/symbols/acme/mod.rs @@ -3,7 +3,6 @@ use std::path::{Path, PathBuf}; use crate::command_runner::CommandRunner; use crate::command_runner::SetuidCommandRunner; -use crate::symbols::concat::Concat; use crate::symbols::dir::Dir; use crate::symbols::file::File; use crate::symbols::list::List; @@ -95,19 +94,4 @@ impl<'a, U: Clone + AsRef, H: AsRef, C: AsRef, R: CommandRunner> AcmeCertChain::new(host, &self.acme_command_runner, root_cert_path), )) } - pub fn get_key_and_cert_bundle>( - &'a self, - host: HOST, - ) -> impl Symbol + 'a { - List::from(( - self.get_cert(host.clone()), - Concat::new( - [ - format!("/etc/ssl/private/{}.key", host.as_ref()), - format!("/etc/ssl/local_certs/{}.chained.crt", host.as_ref()), - ], - format!("/etc/ssl/private/{}.with_key.crt", host.as_ref()), - ), - )) - } } diff --git a/src/symbols/concat.rs b/src/symbols/concat.rs deleted file mode 100644 index 186dbcc..0000000 --- a/src/symbols/concat.rs +++ /dev/null @@ -1,79 +0,0 @@ -use std::error::Error; -use std::fmt; -use std::fs::{metadata, File}; -use std::io::copy; -use std::marker::PhantomData; -use std::path::Path; - -use crate::resources::Resource; -use crate::symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner}; - -pub struct Concat { - target: D, - sources: S, - source_item: PhantomData, -} - -impl Concat { - pub fn new(sources: S, target: D) -> Self { - Self { - target, - sources, - source_item: PhantomData::default(), - } - } -} - -impl, D: AsRef, I: AsRef> Symbol for Concat { - fn target_reached(&self) -> Result> { - let target = self.target.as_ref(); - if !target.exists() { - return Ok(false); - } - let target_date = metadata(target)?.modified()?; - for source in self.sources.as_ref() { - if metadata(source)?.modified()? > target_date { - return Ok(false); - } - } - Ok(true) - } - - fn execute(&self) -> Result<(), Box> { - let mut file = File::create(self.target.as_ref())?; - for source in self.sources.as_ref() { - copy(&mut File::open(source)?, &mut file)?; - } - Ok(()) - } - - fn get_prerequisites(&self) -> Vec { - let mut r: Vec = self - .sources - .as_ref() - .iter() - .map(|s| Resource::new("file", s.as_ref().to_str().unwrap())) - .collect(); - if let Some(parent) = self.target.as_ref().parent() { - r.push(Resource::new("dir", parent.to_str().unwrap())) - } - r - } - - fn as_action<'a>(&'a self, runner: &'a dyn SymbolRunner) -> Box { - Box::new(SymbolAction::new(runner, self)) - } - - fn into_action<'a>(self: Box, runner: &'a dyn SymbolRunner) -> Box - where - Self: 'a, - { - Box::new(OwnedSymbolAction::new(runner, *self)) - } -} - -impl, I> fmt::Display for Concat { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - write!(f, "Concat {}", self.target.as_ref().display()) - } -} diff --git a/src/symbols/factory.rs b/src/symbols/factory.rs index 6331ff7..0f54f70 100644 --- a/src/symbols/factory.rs +++ b/src/symbols/factory.rs @@ -59,20 +59,9 @@ impl<'b, C: 'b + CommandRunner, P: 'b + Policy> SymbolFactory<'b, C, P> { } } - pub fn get_cert<'a, H: 'a + AsRef + Clone>(&'a self, host: H) -> impl Symbol + 'a { - self.acme_factory.get_cert(host) - } - - pub fn get_key_and_cert_bundle<'a, H: 'a + AsRef + Clone>( - &'a self, - host: H, - ) -> impl Symbol + 'a { - self.acme_factory.get_key_and_cert_bundle(host) - } - - pub fn get_nginx_acme_server<'a, S: 'a + Symbol>( - &'a self, - host: &'a str, + pub fn get_nginx_acme_server<'a, 'c: 'a, S: 'a + Symbol>( + &'c self, + host: &'static str, nginx_server_symbol: S, ) -> impl Symbol + 'a { List::from(( @@ -82,7 +71,7 @@ impl<'b, C: 'b + CommandRunner, P: 'b + Policy> SymbolFactory<'b, C, P> { ReloadService::new("nginx", self.command_runner), ), Hook::new( - self.get_cert(host), + self.acme_factory.get_cert(host), ReloadService::new("nginx", self.command_runner), ), )) @@ -165,9 +154,9 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin root_dir, 10, " - location / { + location / {{ try_files $uri $uri/ /index.php?$args; - } + }} ", ) } diff --git a/src/symbols/list.rs b/src/symbols/list.rs index 2df3247..5925971 100644 --- a/src/symbols/list.rs +++ b/src/symbols/list.rs @@ -48,8 +48,6 @@ impl Symbol for List<'_> { for symbol in &self.symbols { if let Some(provides) = symbol.provides() { r.extend(provides.into_iter()); - } else { - return None; } } if r.is_empty() { diff --git a/src/symbols/mod.rs b/src/symbols/mod.rs index 779d186..8c3150f 100644 --- a/src/symbols/mod.rs +++ b/src/symbols/mod.rs @@ -68,7 +68,6 @@ impl<'a, S: Symbol + 'a> Action for OwnedSymbolAction<'a, S> { } pub mod acme; -pub mod concat; pub mod cron; pub mod dir; pub mod factory; diff --git a/src/symbols/tls/key.rs b/src/symbols/tls/key.rs index 70a9b1b..2bd440c 100644 --- a/src/symbols/tls/key.rs +++ b/src/symbols/tls/key.rs @@ -54,7 +54,6 @@ impl Symbol for TlsKey<'_, C> { "-text".as_ref(), ], )?; - // FIXME check bytes Ok(stdout.ends_with("RSA key ok\n".as_bytes())) }