New architecture
This commit is contained in:
parent
e4b3424ba6
commit
907a4962c5
61 changed files with 2742 additions and 3100 deletions
|
|
@ -1,15 +1,282 @@
|
|||
#[derive(PartialEq, Eq, Hash, Clone)]
|
||||
pub struct Resource(pub String, pub String);
|
||||
use crate::artifacts::{
|
||||
DatabaseName as DatabaseNameArtifact, Path as PathArtifact, ServiceName as ServiceNameArtifact,
|
||||
UserName as UserNameArtifact,
|
||||
};
|
||||
use std::hash::Hash;
|
||||
use std::path::PathBuf;
|
||||
|
||||
impl<'a> Resource {
|
||||
pub fn new<A: Into<String>, B: Into<String>>(rtype: A, value: B) -> Self {
|
||||
Self(rtype.into(), value.into())
|
||||
}
|
||||
pub trait Resource {
|
||||
type Artifact;
|
||||
}
|
||||
|
||||
pub fn get_type(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
pub fn get_value(&self) -> &str {
|
||||
&self.1
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct Key<D>(pub D);
|
||||
impl<D> Resource for Key<D> {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct Csr<D>(pub D);
|
||||
impl<D> Resource for Csr<D> {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct Cert<D>(pub D);
|
||||
impl<D> Resource for Cert<D> {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct CertChain<D>(pub D);
|
||||
impl<D> Resource for CertChain<D> {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct KeyAndCertBundle<D>(pub D);
|
||||
impl<D> Resource for KeyAndCertBundle<D> {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct File<P>(pub P, pub String);
|
||||
impl<'a, P> Resource for File<P> {
|
||||
type Artifact = ();
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct GitCheckout<'a, P>(pub P, pub &'a str, pub &'a str);
|
||||
impl<'a, P> Resource for GitCheckout<'a, P> {
|
||||
type Artifact = ();
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct Dir<P>(pub P);
|
||||
impl<P> Resource for Dir<P> {
|
||||
type Artifact = ();
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct UserForDomain<D>(pub D);
|
||||
impl<D> Resource for UserForDomain<D> {
|
||||
type Artifact = (UserNameArtifact, PathArtifact);
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct AcmeAccountKey;
|
||||
impl Resource for AcmeAccountKey {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct AcmeUser;
|
||||
impl Resource for AcmeUser {
|
||||
type Artifact = UserNameArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct AcmeRootCert;
|
||||
impl Resource for AcmeRootCert {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct AcmeChallengesDir;
|
||||
impl Resource for AcmeChallengesDir {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct AcmeChallengesNginxSnippet;
|
||||
impl Resource for AcmeChallengesNginxSnippet {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct StoredDirectory<P>(pub &'static str, pub P);
|
||||
impl<P> Resource for StoredDirectory<P> {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct LoadedDirectory<P>(pub &'static str, pub P);
|
||||
impl<P> Resource for LoadedDirectory<P> {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
pub fn get_saved_directory<P: Clone>(
|
||||
storage_name: &'static str,
|
||||
target: P,
|
||||
) -> (StoredDirectory<P>, LoadedDirectory<P>) {
|
||||
(
|
||||
StoredDirectory(storage_name, target.clone()),
|
||||
LoadedDirectory(storage_name, target),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct User(pub String);
|
||||
impl Resource for User {
|
||||
type Artifact = ();
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct SystemdSocketService<D, P>(pub D, pub &'static str, pub P, pub P, pub bool);
|
||||
impl<D, P> Resource for SystemdSocketService<D, P> {
|
||||
type Artifact = (PathArtifact, PathArtifact, UserNameArtifact);
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct NpmInstall<P>(pub P);
|
||||
impl<P> Resource for NpmInstall<P> {
|
||||
type Artifact = ();
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct Owner<P>(pub String, pub P);
|
||||
impl<P> Resource for Owner<P> {
|
||||
type Artifact = ();
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct ServeCustom<D>(pub D, pub String);
|
||||
impl<D> Resource for ServeCustom<D> {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct ServePhp<D, P>(pub D, pub P, pub &'static str, pub String, pub usize);
|
||||
impl<D, P> Resource for ServePhp<D, P> {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
// Domain, service name, exec, static, dir
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct ServeService<D, P>(pub D, pub &'static str, pub P, pub P, pub P, pub bool);
|
||||
impl<D, P> Resource for ServeService<D, P> {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct ServeRedir<D>(pub D, pub D);
|
||||
impl<D> Resource for ServeRedir<D> {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct ServeStatic<D, P>(pub D, pub P);
|
||||
impl<D, P> Resource for ServeStatic<D, P> {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct DefaultServer;
|
||||
impl Resource for DefaultServer {
|
||||
type Artifact = PathArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct PhpFpmPool<D>(pub D, pub usize);
|
||||
impl<D> Resource for PhpFpmPool<D> {
|
||||
type Artifact = (
|
||||
PathArtifact,
|
||||
PathArtifact,
|
||||
UserNameArtifact,
|
||||
ServiceNameArtifact,
|
||||
);
|
||||
}
|
||||
|
||||
// A single domain could possibly need multiple databases
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct MariaDbDatabase<D>(pub D);
|
||||
impl<D> Resource for MariaDbDatabase<D> {
|
||||
type Artifact = (DatabaseNameArtifact, UserNameArtifact, PathArtifact);
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct MariaDbUser<D>(pub D);
|
||||
impl<D> Resource for MariaDbUser<D> {
|
||||
type Artifact = UserNameArtifact;
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct WordpressPlugin<P>(pub P, pub &'static str);
|
||||
impl<P> Resource for WordpressPlugin<P> {
|
||||
type Artifact = ();
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct WordpressTranslation<P>(pub P, pub &'static str, pub &'static str);
|
||||
impl<P> Resource for WordpressTranslation<P> {
|
||||
type Artifact = ();
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||
pub struct Cron<D>(pub D, pub String);
|
||||
impl<D> Resource for Cron<D> {
|
||||
type Artifact = ();
|
||||
}
|
||||
|
||||
pub trait BorrowResource<R> {
|
||||
fn borrow_resource(&self) -> Option<&R>;
|
||||
}
|
||||
|
||||
macro_rules! default_resources {
|
||||
( $($name:ident: $type:ty,)* ) => {
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub enum DefaultResources<'a, D> {
|
||||
$( $name($type) ),*
|
||||
}
|
||||
|
||||
$(impl<'a, D> From<$type> for DefaultResources<'a, D> {
|
||||
fn from(from: $type) -> Self {
|
||||
Self::$name(from)
|
||||
}
|
||||
})*
|
||||
|
||||
$(impl<'a, D> BorrowResource<$type> for DefaultResources<'a, D> {
|
||||
fn borrow_resource(&self) -> Option<&$type> {
|
||||
match self {
|
||||
Self::$name(v) => Some(v),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
})*
|
||||
}
|
||||
}
|
||||
|
||||
default_resources!(
|
||||
AcmeAccountKey: AcmeAccountKey,
|
||||
AcmeChallengesDir: AcmeChallengesDir,
|
||||
AcmeChallengesNginxSnippet: AcmeChallengesNginxSnippet,
|
||||
AcmeRootCert: AcmeRootCert,
|
||||
AcmeUser: AcmeUser,
|
||||
Cert: Cert<D>,
|
||||
CertChain: CertChain<D>,
|
||||
Cron: Cron<D>,
|
||||
Csr: Csr<D>,
|
||||
DefaultServer: DefaultServer,
|
||||
Dir: Dir<PathBuf>,
|
||||
File: File<PathBuf>,
|
||||
GitCheckout: GitCheckout<'a, PathBuf>,
|
||||
Key: Key<D>,
|
||||
KeyAndCertBundle: KeyAndCertBundle<D>,
|
||||
LoadedDirectory: LoadedDirectory<PathBuf>,
|
||||
MariaDbDatabase: MariaDbDatabase<D>,
|
||||
MariaDbUser: MariaDbUser<D>,
|
||||
SystemdSocketService: SystemdSocketService<D, PathBuf>,
|
||||
NpmInstall: NpmInstall<PathBuf>,
|
||||
Owner: Owner<PathBuf>,
|
||||
PhpFpmPool: PhpFpmPool<D>,
|
||||
ServeCustom: ServeCustom<D>,
|
||||
ServeService: ServeService<D, PathBuf>,
|
||||
ServePhp: ServePhp<D, PathBuf>,
|
||||
ServeRedir: ServeRedir<D>,
|
||||
ServeStatic: ServeStatic<D, PathBuf>,
|
||||
StoredDirectory: StoredDirectory<PathBuf>,
|
||||
User: User,
|
||||
UserForDomain: UserForDomain<D>,
|
||||
WordpressPlugin: WordpressPlugin<PathBuf>,
|
||||
WordpressTranslation: WordpressTranslation<PathBuf>,
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue