Add postgresql database
This commit is contained in:
parent
d7180e327a
commit
b53267f406
3 changed files with 53 additions and 4 deletions
|
|
@ -2,12 +2,13 @@ use crate::command_runner::{SetuidCommandRunner, StdCommandRunner};
|
||||||
use crate::resources::{
|
use crate::resources::{
|
||||||
AcmeAccountKey, AcmeChallengesDir, AcmeChallengesNginxSnippet, AcmeRootCert, AcmeUser, Cert,
|
AcmeAccountKey, AcmeChallengesDir, AcmeChallengesNginxSnippet, AcmeRootCert, AcmeUser, Cert,
|
||||||
CertChain, Cron, Csr, DefaultServer, Dir, File, GitCheckout, Key, KeyAndCertBundle,
|
CertChain, Cron, Csr, DefaultServer, Dir, File, GitCheckout, Key, KeyAndCertBundle,
|
||||||
LoadedDirectory, MariaDbDatabase, MariaDbUser, NpmInstall, Owner, PhpFpmPool, Resource,
|
LoadedDirectory, MariaDbDatabase, MariaDbUser, NpmInstall, Owner, PhpFpmPool, PostgresqlDatabase,
|
||||||
ServeCustom, ServePhp, ServeRedir, ServeService, ServeStatic, StoredDirectory,
|
Resource, ServeCustom, ServePhp, ServeRedir, ServeService, ServeStatic, StoredDirectory,
|
||||||
SystemdSocketService, User, UserForDomain, WordpressPlugin, WordpressTranslation,
|
SystemdSocketService, User, UserForDomain, WordpressPlugin, WordpressTranslation,
|
||||||
};
|
};
|
||||||
use crate::static_files::LETS_ENCRYPT_X3_CROSS_SIGNED;
|
use crate::static_files::LETS_ENCRYPT_X3_CROSS_SIGNED;
|
||||||
use crate::storage::SimpleStorage;
|
use crate::storage::SimpleStorage;
|
||||||
|
use crate::storage::Storage;
|
||||||
use crate::symbols::acme::Cert as CertSymbol;
|
use crate::symbols::acme::Cert as CertSymbol;
|
||||||
use crate::symbols::concat::Concat as ConcatSymbol;
|
use crate::symbols::concat::Concat as ConcatSymbol;
|
||||||
use crate::symbols::cron::Cron as CronSymbol;
|
use crate::symbols::cron::Cron as CronSymbol;
|
||||||
|
|
@ -19,6 +20,7 @@ use crate::symbols::mariadb::{
|
||||||
};
|
};
|
||||||
use crate::symbols::npm::Install as NpmInstallSymbol;
|
use crate::symbols::npm::Install as NpmInstallSymbol;
|
||||||
use crate::symbols::owner::Owner as OwnerSymbol;
|
use crate::symbols::owner::Owner as OwnerSymbol;
|
||||||
|
use crate::symbols::postgresql::PostgreSQLDatabase as PostgreSQLDatabaseSymbol;
|
||||||
use crate::symbols::saved_directory::{SavedDirectory as SavedDirectorySymbol, StorageDirection};
|
use crate::symbols::saved_directory::{SavedDirectory as SavedDirectorySymbol, StorageDirection};
|
||||||
use crate::symbols::systemd::{
|
use crate::symbols::systemd::{
|
||||||
ReloadService as ReloadServiceSymbol, UserService as UserServiceSymbol,
|
ReloadService as ReloadServiceSymbol, UserService as UserServiceSymbol,
|
||||||
|
|
@ -715,6 +717,27 @@ 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 {
|
||||||
|
()
|
||||||
|
}
|
||||||
|
|
||||||
|
type Implementation = (PostgreSQLDatabaseSymbol<'static, String, String, StdCommandRunner>,);
|
||||||
|
fn create(
|
||||||
|
_resource: &PostgresqlDatabase<D>,
|
||||||
|
(db_name, data_path): &<PostgresqlDatabase<D> as Resource>::Artifact,
|
||||||
|
_: <Self::Prerequisites as ToArtifact>::Artifact,
|
||||||
|
) -> Self::Implementation {
|
||||||
|
let db_dump = SimpleStorage::new(data_path.clone().into());
|
||||||
|
(PostgreSQLDatabaseSymbol::new(
|
||||||
|
db_name.0.clone(),
|
||||||
|
db_dump.read_filename().unwrap().to_str().unwrap().into(),
|
||||||
|
&StdCommandRunner,
|
||||||
|
),)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<P: Clone + AsRef<Path>> ImplementationBuilder<WordpressPlugin<P>> for DefaultBuilder {
|
impl<P: Clone + AsRef<Path>> ImplementationBuilder<WordpressPlugin<P>> for DefaultBuilder {
|
||||||
type Prerequisites = Dir<PathBuf>;
|
type Prerequisites = Dir<PathBuf>;
|
||||||
fn prerequisites(resource: &WordpressPlugin<P>) -> Self::Prerequisites {
|
fn prerequisites(resource: &WordpressPlugin<P>) -> Self::Prerequisites {
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ use crate::artifacts::{
|
||||||
use crate::resources::{
|
use crate::resources::{
|
||||||
AcmeAccountKey, AcmeChallengesDir, AcmeChallengesNginxSnippet, AcmeRootCert, AcmeUser, Cert,
|
AcmeAccountKey, AcmeChallengesDir, AcmeChallengesNginxSnippet, AcmeRootCert, AcmeUser, Cert,
|
||||||
CertChain, Cron, Csr, DefaultServer, Dir, File, GitCheckout, Key, KeyAndCertBundle,
|
CertChain, Cron, Csr, DefaultServer, Dir, File, GitCheckout, Key, KeyAndCertBundle,
|
||||||
LoadedDirectory, MariaDbDatabase, MariaDbUser, NpmInstall, Owner, PhpFpmPool, Resource,
|
LoadedDirectory, MariaDbDatabase, MariaDbUser, NpmInstall, Owner, PhpFpmPool, PostgresqlDatabase,
|
||||||
ServeCustom, ServePhp, ServeRedir, ServeService, ServeStatic, StoredDirectory,
|
Resource, ServeCustom, ServePhp, ServeRedir, ServeService, ServeStatic, StoredDirectory,
|
||||||
SystemdSocketService, User, UserForDomain, WordpressPlugin, WordpressTranslation,
|
SystemdSocketService, User, UserForDomain, WordpressPlugin, WordpressTranslation,
|
||||||
};
|
};
|
||||||
use crate::to_artifact::ToArtifact;
|
use crate::to_artifact::ToArtifact;
|
||||||
|
|
@ -422,6 +422,25 @@ impl<D: AsRef<str>, P: Policy> ResourceLocator<MariaDbUser<D>> for DefaultLocato
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<D: AsRef<str>, P: Policy> ResourceLocator<PostgresqlDatabase<D>> for DefaultLocator<P> {
|
||||||
|
type Prerequisites = ();
|
||||||
|
fn locate(
|
||||||
|
resource: &PostgresqlDatabase<D>,
|
||||||
|
) -> (
|
||||||
|
<PostgresqlDatabase<D> as Resource>::Artifact,
|
||||||
|
Self::Prerequisites,
|
||||||
|
) {
|
||||||
|
let ((user_name, _), ()) = Self::locate(&UserForDomain(&resource.0));
|
||||||
|
(
|
||||||
|
(
|
||||||
|
DatabaseNameArtifact(user_name.0.clone()),
|
||||||
|
PathArtifact::from(P::path_for_data(format!("{}.sql", user_name.0))),
|
||||||
|
),
|
||||||
|
(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<P, POLICY> ResourceLocator<WordpressPlugin<P>> for DefaultLocator<POLICY> {
|
impl<P, POLICY> ResourceLocator<WordpressPlugin<P>> for DefaultLocator<POLICY> {
|
||||||
type Prerequisites = ();
|
type Prerequisites = ();
|
||||||
fn locate(
|
fn locate(
|
||||||
|
|
|
||||||
|
|
@ -200,6 +200,12 @@ impl<D> Resource for MariaDbUser<D> {
|
||||||
type Artifact = UserNameArtifact;
|
type Artifact = UserNameArtifact;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||||
|
pub struct PostgresqlDatabase<D>(pub D);
|
||||||
|
impl<D> Resource for PostgresqlDatabase<D> {
|
||||||
|
type Artifact = (DatabaseNameArtifact, PathArtifact);
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Hash, PartialEq, Eq)]
|
#[derive(Debug, Hash, PartialEq, Eq)]
|
||||||
pub struct WordpressPlugin<P>(pub P, pub &'static str);
|
pub struct WordpressPlugin<P>(pub P, pub &'static str);
|
||||||
impl<P> Resource for WordpressPlugin<P> {
|
impl<P> Resource for WordpressPlugin<P> {
|
||||||
|
|
@ -288,6 +294,7 @@ default_resources!(
|
||||||
LoadedDirectory: LoadedDirectory<PathBuf>,
|
LoadedDirectory: LoadedDirectory<PathBuf>,
|
||||||
MariaDbDatabase: MariaDbDatabase<D>,
|
MariaDbDatabase: MariaDbDatabase<D>,
|
||||||
MariaDbUser: MariaDbUser<D>,
|
MariaDbUser: MariaDbUser<D>,
|
||||||
|
PostgresqlDatabase: PostgresqlDatabase<D>,
|
||||||
SystemdSocketService: SystemdSocketService<D, PathBuf>,
|
SystemdSocketService: SystemdSocketService<D, PathBuf>,
|
||||||
NpmInstall: NpmInstall<PathBuf>,
|
NpmInstall: NpmInstall<PathBuf>,
|
||||||
Owner: Owner<PathBuf>,
|
Owner: Owner<PathBuf>,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue