This commit is contained in:
Adrian Heine 2020-10-17 23:44:52 +02:00
parent b53267f406
commit 0d836b899f
5 changed files with 37 additions and 35 deletions

View file

@ -719,7 +719,7 @@ impl<D: Clone> ImplementationBuilder<MariaDbDatabase<D>> for DefaultBuilder {
impl<D: Clone> ImplementationBuilder<PostgresqlDatabase<D>> for DefaultBuilder {
type Prerequisites = ();
fn prerequisites(resource: &PostgresqlDatabase<D>) -> Self::Prerequisites {
fn prerequisites(_: &PostgresqlDatabase<D>) -> Self::Prerequisites {
()
}

View file

@ -125,8 +125,8 @@ impl<U: AsRef<str>, C: CommandRunner> CommandRunner for SetuidCommandRunner<'_,
let uid = get_user_by_name(self.user_name.as_ref())
.expect("User does not exist")
.uid();
let _set_home = TempSetEnv::new("HOME", format!("/home/{}", self.user_name.as_ref()));
let _set_dbus = TempSetEnv::new("XDG_RUNTIME_DIR", format!("/run/user/{}", uid));
let set_home = TempSetEnv::new("HOME", format!("/home/{}", self.user_name.as_ref()));
let set_dbus = TempSetEnv::new("XDG_RUNTIME_DIR", format!("/run/user/{}", uid));
//println!("{} {:?}", program, args);
let mut child = Command::new(program)
.args(args)
@ -143,6 +143,8 @@ impl<U: AsRef<str>, C: CommandRunner> CommandRunner for SetuidCommandRunner<'_,
.await
.expect("Failed to write to stdin");
let res = child.wait_with_output().await;
drop(set_home);
drop(set_dbus);
//println!("{:?}", res);
res
}

View file

@ -15,23 +15,29 @@ use std::marker::PhantomData;
use std::path::{Path, PathBuf};
pub trait Policy {
#[must_use]
fn acme_user() -> &'static str {
"acme"
}
#[must_use]
fn user_home(user_name: &str) -> PathBuf {
format!("/home/{}", user_name).into()
Path::new("/home").join(user_name)
}
#[must_use]
fn user_name_for_domain(domain_name: &'_ str) -> String {
domain_name.split('.').rev().fold(String::new(), |result, part| if result.is_empty() { result } else { result + "_" } + part)
}
#[must_use]
fn php_version() -> &'static str {
"7.0"
}
#[must_use]
fn path_for_data(name: impl Display) -> PathBuf {
("/root/data".as_ref() as &Path).join(format!("_{}", name))
Path::new("/root/data").join(format!("_{}", name))
}
}
@ -286,7 +292,7 @@ impl<D: AsRef<Path>, POLICY> ResourceLocator<ServeCustom<D>> for DefaultLocator<
resource: &ServeCustom<D>,
) -> (<ServeCustom<D> as Resource>::Artifact, Self::Prerequisites) {
(
PathArtifact::from(("/etc/nginx/sites-enabled/".as_ref() as &Path).join(&resource.0)),
PathArtifact::from(Path::new("/etc/nginx/sites-enabled/").join(&resource.0)),
(),
)
}
@ -298,7 +304,7 @@ impl<D: AsRef<Path>, P, POLICY> ResourceLocator<ServePhp<D, P>> for DefaultLocat
resource: &ServePhp<D, P>,
) -> (<ServePhp<D, P> as Resource>::Artifact, Self::Prerequisites) {
(
PathArtifact::from(("/etc/nginx/sites-enabled/".as_ref() as &Path).join(&resource.0)),
PathArtifact::from(Path::new("/etc/nginx/sites-enabled/").join(&resource.0)),
(),
)
}
@ -313,7 +319,7 @@ impl<D: AsRef<Path>, P, POLICY> ResourceLocator<ServeService<D, P>> for DefaultL
Self::Prerequisites,
) {
(
PathArtifact::from(("/etc/nginx/sites-enabled/".as_ref() as &Path).join(&resource.0)),
PathArtifact::from(Path::new("/etc/nginx/sites-enabled/").join(&resource.0)),
(),
)
}
@ -325,7 +331,7 @@ impl<D: AsRef<Path>, POLICY> ResourceLocator<ServeRedir<D>> for DefaultLocator<P
resource: &ServeRedir<D>,
) -> (<ServeRedir<D> as Resource>::Artifact, Self::Prerequisites) {
(
PathArtifact::from(("/etc/nginx/sites-enabled/".as_ref() as &Path).join(&resource.0)),
PathArtifact::from(Path::new("/etc/nginx/sites-enabled/").join(&resource.0)),
(),
)
}
@ -340,7 +346,7 @@ impl<D: AsRef<Path>, P, POLICY> ResourceLocator<ServeStatic<D, P>> for DefaultLo
Self::Prerequisites,
) {
(
PathArtifact::from(("/etc/nginx/sites-enabled/".as_ref() as &Path).join(&resource.0)),
PathArtifact::from(Path::new("/etc/nginx/sites-enabled/").join(&resource.0)),
(),
)
}

View file

@ -17,27 +17,14 @@ pub trait SymbolRunner {
) -> Result<bool, Box<dyn Error>>;
}
#[derive(Debug)]
pub enum SymbolRunError {
Symbol(Box<dyn Error>),
ExecuteDidNotReach(()),
}
#[derive(Debug, Default)]
pub struct ExecuteDidNotReachError;
impl Error for SymbolRunError {
fn cause(&self) -> Option<&dyn Error> {
match self {
Self::Symbol(ref e) => Some(&**e),
Self::ExecuteDidNotReach(_) => None,
}
}
}
impl Error for ExecuteDidNotReachError {}
impl fmt::Display for SymbolRunError {
impl fmt::Display for ExecuteDidNotReachError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Symbol(ref e) => write!(f, "{}", e),
Self::ExecuteDidNotReach(_) => write!(f, "Target not reached after executing symbol"),
}
write!(f, "Target not reached after executing symbol")
}
}
@ -45,7 +32,8 @@ impl fmt::Display for SymbolRunError {
pub struct InitializingSymbolRunner;
impl InitializingSymbolRunner {
pub fn new() -> Self {
#[must_use]
pub const fn new() -> Self {
Self
}
@ -64,7 +52,7 @@ impl InitializingSymbolRunner {
if target_reached {
Ok(())
} else {
Err(Box::new(SymbolRunError::ExecuteDidNotReach(())))
Err(Box::new(ExecuteDidNotReachError))
}
}
}
@ -102,7 +90,8 @@ impl SymbolRunner for InitializingSymbolRunner {
pub struct DelayingSymbolRunner<R>(R);
impl<R> DelayingSymbolRunner<R> {
pub fn new(symbol_runner: R) -> Self {
#[must_use]
pub const fn new(symbol_runner: R) -> Self {
Self(symbol_runner)
}
}
@ -137,7 +126,8 @@ where
pub struct DrySymbolRunner;
impl DrySymbolRunner {
pub fn new() -> Self {
#[must_use]
pub const fn new() -> Self {
Self
}
}
@ -172,7 +162,8 @@ impl SymbolRunner for DrySymbolRunner {
pub struct ReportingSymbolRunner<R>(R);
impl<R> ReportingSymbolRunner<R> {
pub fn new(symbol_runner: R) -> Self {
#[must_use]
pub const fn new(symbol_runner: R) -> Self {
Self(symbol_runner)
}
}
@ -251,6 +242,7 @@ mod test {
T: Iterator<Item = Result<bool, Box<dyn Error>>>,
> DummySymbol<T, E>
{
#[must_use]
fn new<
IE: IntoIterator<IntoIter = E, Item = Result<(), Box<dyn Error>>>,
IT: IntoIterator<IntoIter = T, Item = Result<bool, Box<dyn Error>>>,

View file

@ -41,7 +41,7 @@ impl<U: AsRef<str>, C: CommandRunner> Symbol for User<U, C> {
// adduser is not reentrant because finding the next uid
// and creating the account is not an atomic operation
let wait = WAIT.acquire().await;
self
let res = self
.command_runner
.run_successfully(
"adduser",
@ -51,7 +51,9 @@ impl<U: AsRef<str>, C: CommandRunner> Symbol for User<U, C> {
self.user_name.as_ref(),
],
)
.await
.await;
drop(wait);
res
}
}