You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.1 KiB
66 lines
2.1 KiB
use std::borrow::{Borrow, Cow};
|
|
use std::error::Error;
|
|
use std::fmt;
|
|
use std::ops::Deref;
|
|
use std::path::PathBuf;
|
|
use resources::Resource;
|
|
|
|
use command_runner::CommandRunner;
|
|
use symbols::{Action, OwnedSymbolAction, SymbolAction, SymbolRunner, Symbol};
|
|
use symbols::acme::AcmeAccountKey;
|
|
use symbols::dir::Dir;
|
|
use symbols::file::File;
|
|
use symbols::hook::Hook;
|
|
use symbols::list::List;
|
|
use symbols::owner::Owner;
|
|
|
|
pub struct AcmeUser<'a>(Cow<'a, str>);
|
|
|
|
impl<'a> AcmeUser<'a> {
|
|
pub fn new<S: Into<Cow<'a, str>>>(user_name: S) -> Self {
|
|
AcmeUser(user_name.into())
|
|
}
|
|
}
|
|
|
|
impl<'a> Symbol for AcmeUser<'a> {
|
|
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
|
Ok(false)
|
|
}
|
|
fn execute(&self) -> Result<(), Box<Error>> {
|
|
Ok(())
|
|
}
|
|
fn get_prerequisites(&self) -> Vec<Resource> {
|
|
vec![]
|
|
}
|
|
fn provides(&self) -> Option<Vec<Resource>> {
|
|
None
|
|
}
|
|
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
|
|
Box::new(SymbolAction::new(runner, self))
|
|
}
|
|
|
|
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
|
|
Box::new(OwnedSymbolAction::new(runner, *self))
|
|
}
|
|
}
|
|
|
|
impl<'a> fmt::Display for AcmeUser<'a> {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(f, "AcmeUser {}", self.0)
|
|
}
|
|
}
|
|
|
|
pub fn new<'a, S: Into<Cow<'a, str>>, C: CommandRunner, P: 'a + Deref<Target=str>>(command_runner: &'a C, cert: P, user_name: S) -> Box<Symbol + 'a> { // impl trait
|
|
let user_name_cow = user_name.into();
|
|
let account_key_file: PathBuf = ["/home", user_name_cow.borrow(), "account.key"].iter().collect();
|
|
Box::new(List::new(vec![
|
|
Box::new(AcmeAccountKey::new(account_key_file.clone().into(), command_runner)),
|
|
Box::new(Owner::new(account_key_file.to_string_lossy().into_owned(), user_name_cow.clone(), command_runner)),
|
|
Box::new(Dir::new("/home/acme/challenges")),
|
|
Box::new(Owner::new("/home/acme/challenges", user_name_cow.clone(), command_runner)),
|
|
Box::new(Dir::new("/etc/ssl/local_certs")),
|
|
Box::new(Owner::new("/etc/ssl/local_certs", user_name_cow, command_runner)),
|
|
Box::new(File::new("/home/acme/lets_encrypt_x3_cross_signed.pem", cert))
|
|
]))
|
|
}
|
|
|