Style
This commit is contained in:
parent
b53267f406
commit
0d836b899f
5 changed files with 37 additions and 35 deletions
|
|
@ -719,7 +719,7 @@ impl<D: Clone> ImplementationBuilder<MariaDbDatabase<D>> for DefaultBuilder {
|
||||||
|
|
||||||
impl<D: Clone> ImplementationBuilder<PostgresqlDatabase<D>> for DefaultBuilder {
|
impl<D: Clone> ImplementationBuilder<PostgresqlDatabase<D>> for DefaultBuilder {
|
||||||
type Prerequisites = ();
|
type Prerequisites = ();
|
||||||
fn prerequisites(resource: &PostgresqlDatabase<D>) -> Self::Prerequisites {
|
fn prerequisites(_: &PostgresqlDatabase<D>) -> Self::Prerequisites {
|
||||||
()
|
()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -125,8 +125,8 @@ impl<U: AsRef<str>, C: CommandRunner> CommandRunner for SetuidCommandRunner<'_,
|
||||||
let uid = get_user_by_name(self.user_name.as_ref())
|
let uid = get_user_by_name(self.user_name.as_ref())
|
||||||
.expect("User does not exist")
|
.expect("User does not exist")
|
||||||
.uid();
|
.uid();
|
||||||
let _set_home = TempSetEnv::new("HOME", format!("/home/{}", self.user_name.as_ref()));
|
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_dbus = TempSetEnv::new("XDG_RUNTIME_DIR", format!("/run/user/{}", uid));
|
||||||
//println!("{} {:?}", program, args);
|
//println!("{} {:?}", program, args);
|
||||||
let mut child = Command::new(program)
|
let mut child = Command::new(program)
|
||||||
.args(args)
|
.args(args)
|
||||||
|
|
@ -143,6 +143,8 @@ impl<U: AsRef<str>, C: CommandRunner> CommandRunner for SetuidCommandRunner<'_,
|
||||||
.await
|
.await
|
||||||
.expect("Failed to write to stdin");
|
.expect("Failed to write to stdin");
|
||||||
let res = child.wait_with_output().await;
|
let res = child.wait_with_output().await;
|
||||||
|
drop(set_home);
|
||||||
|
drop(set_dbus);
|
||||||
//println!("{:?}", res);
|
//println!("{:?}", res);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,23 +15,29 @@ use std::marker::PhantomData;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
pub trait Policy {
|
pub trait Policy {
|
||||||
|
#[must_use]
|
||||||
fn acme_user() -> &'static str {
|
fn acme_user() -> &'static str {
|
||||||
"acme"
|
"acme"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
fn user_home(user_name: &str) -> PathBuf {
|
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 {
|
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)
|
domain_name.split('.').rev().fold(String::new(), |result, part| if result.is_empty() { result } else { result + "_" } + part)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
fn php_version() -> &'static str {
|
fn php_version() -> &'static str {
|
||||||
"7.0"
|
"7.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
fn path_for_data(name: impl Display) -> PathBuf {
|
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>,
|
resource: &ServeCustom<D>,
|
||||||
) -> (<ServeCustom<D> as Resource>::Artifact, Self::Prerequisites) {
|
) -> (<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>,
|
resource: &ServePhp<D, P>,
|
||||||
) -> (<ServePhp<D, P> as Resource>::Artifact, Self::Prerequisites) {
|
) -> (<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,
|
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>,
|
resource: &ServeRedir<D>,
|
||||||
) -> (<ServeRedir<D> as Resource>::Artifact, Self::Prerequisites) {
|
) -> (<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,
|
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)),
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,27 +17,14 @@ pub trait SymbolRunner {
|
||||||
) -> Result<bool, Box<dyn Error>>;
|
) -> Result<bool, Box<dyn Error>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub enum SymbolRunError {
|
pub struct ExecuteDidNotReachError;
|
||||||
Symbol(Box<dyn Error>),
|
|
||||||
ExecuteDidNotReach(()),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Error for SymbolRunError {
|
impl Error for ExecuteDidNotReachError {}
|
||||||
fn cause(&self) -> Option<&dyn Error> {
|
|
||||||
match self {
|
|
||||||
Self::Symbol(ref e) => Some(&**e),
|
|
||||||
Self::ExecuteDidNotReach(_) => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for SymbolRunError {
|
impl fmt::Display for ExecuteDidNotReachError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
write!(f, "Target not reached after executing symbol")
|
||||||
Self::Symbol(ref e) => write!(f, "{}", e),
|
|
||||||
Self::ExecuteDidNotReach(_) => write!(f, "Target not reached after executing symbol"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,7 +32,8 @@ impl fmt::Display for SymbolRunError {
|
||||||
pub struct InitializingSymbolRunner;
|
pub struct InitializingSymbolRunner;
|
||||||
|
|
||||||
impl InitializingSymbolRunner {
|
impl InitializingSymbolRunner {
|
||||||
pub fn new() -> Self {
|
#[must_use]
|
||||||
|
pub const fn new() -> Self {
|
||||||
Self
|
Self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +52,7 @@ impl InitializingSymbolRunner {
|
||||||
if target_reached {
|
if target_reached {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(Box::new(SymbolRunError::ExecuteDidNotReach(())))
|
Err(Box::new(ExecuteDidNotReachError))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +90,8 @@ impl SymbolRunner for InitializingSymbolRunner {
|
||||||
pub struct DelayingSymbolRunner<R>(R);
|
pub struct DelayingSymbolRunner<R>(R);
|
||||||
|
|
||||||
impl<R> DelayingSymbolRunner<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)
|
Self(symbol_runner)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +126,8 @@ where
|
||||||
pub struct DrySymbolRunner;
|
pub struct DrySymbolRunner;
|
||||||
|
|
||||||
impl DrySymbolRunner {
|
impl DrySymbolRunner {
|
||||||
pub fn new() -> Self {
|
#[must_use]
|
||||||
|
pub const fn new() -> Self {
|
||||||
Self
|
Self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -172,7 +162,8 @@ impl SymbolRunner for DrySymbolRunner {
|
||||||
pub struct ReportingSymbolRunner<R>(R);
|
pub struct ReportingSymbolRunner<R>(R);
|
||||||
|
|
||||||
impl<R> ReportingSymbolRunner<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)
|
Self(symbol_runner)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -251,6 +242,7 @@ mod test {
|
||||||
T: Iterator<Item = Result<bool, Box<dyn Error>>>,
|
T: Iterator<Item = Result<bool, Box<dyn Error>>>,
|
||||||
> DummySymbol<T, E>
|
> DummySymbol<T, E>
|
||||||
{
|
{
|
||||||
|
#[must_use]
|
||||||
fn new<
|
fn new<
|
||||||
IE: IntoIterator<IntoIter = E, Item = Result<(), Box<dyn Error>>>,
|
IE: IntoIterator<IntoIter = E, Item = Result<(), Box<dyn Error>>>,
|
||||||
IT: IntoIterator<IntoIter = T, Item = Result<bool, Box<dyn Error>>>,
|
IT: IntoIterator<IntoIter = T, Item = Result<bool, Box<dyn Error>>>,
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ impl<U: AsRef<str>, C: CommandRunner> Symbol for User<U, C> {
|
||||||
// adduser is not reentrant because finding the next uid
|
// adduser is not reentrant because finding the next uid
|
||||||
// and creating the account is not an atomic operation
|
// and creating the account is not an atomic operation
|
||||||
let wait = WAIT.acquire().await;
|
let wait = WAIT.acquire().await;
|
||||||
self
|
let res = self
|
||||||
.command_runner
|
.command_runner
|
||||||
.run_successfully(
|
.run_successfully(
|
||||||
"adduser",
|
"adduser",
|
||||||
|
|
@ -51,7 +51,9 @@ impl<U: AsRef<str>, C: CommandRunner> Symbol for User<U, C> {
|
||||||
self.user_name.as_ref(),
|
self.user_name.as_ref(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.await
|
.await;
|
||||||
|
drop(wait);
|
||||||
|
res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue