Browse Source

Add postgresql database

master
Adrian Heine 2 years ago
parent
commit
b53267f406
  1. 27
      src/builder.rs
  2. 23
      src/locator.rs
  3. 7
      src/resources/mod.rs

27
src/builder.rs

@ -2,12 +2,13 @@ use crate::command_runner::{SetuidCommandRunner, StdCommandRunner};
use crate::resources::{
AcmeAccountKey, AcmeChallengesDir, AcmeChallengesNginxSnippet, AcmeRootCert, AcmeUser, Cert,
CertChain, Cron, Csr, DefaultServer, Dir, File, GitCheckout, Key, KeyAndCertBundle,
LoadedDirectory, MariaDbDatabase, MariaDbUser, NpmInstall, Owner, PhpFpmPool, Resource,
ServeCustom, ServePhp, ServeRedir, ServeService, ServeStatic, StoredDirectory,
LoadedDirectory, MariaDbDatabase, MariaDbUser, NpmInstall, Owner, PhpFpmPool, PostgresqlDatabase,
Resource, ServeCustom, ServePhp, ServeRedir, ServeService, ServeStatic, StoredDirectory,
SystemdSocketService, User, UserForDomain, WordpressPlugin, WordpressTranslation,
};
use crate::static_files::LETS_ENCRYPT_X3_CROSS_SIGNED;
use crate::storage::SimpleStorage;
use crate::storage::Storage;
use crate::symbols::acme::Cert as CertSymbol;
use crate::symbols::concat::Concat as ConcatSymbol;
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::owner::Owner as OwnerSymbol;
use crate::symbols::postgresql::PostgreSQLDatabase as PostgreSQLDatabaseSymbol;
use crate::symbols::saved_directory::{SavedDirectory as SavedDirectorySymbol, StorageDirection};
use crate::symbols::systemd::{
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 {
type Prerequisites = Dir<PathBuf>;
fn prerequisites(resource: &WordpressPlugin<P>) -> Self::Prerequisites {

23
src/locator.rs

@ -5,8 +5,8 @@ use crate::artifacts::{
use crate::resources::{
AcmeAccountKey, AcmeChallengesDir, AcmeChallengesNginxSnippet, AcmeRootCert, AcmeUser, Cert,
CertChain, Cron, Csr, DefaultServer, Dir, File, GitCheckout, Key, KeyAndCertBundle,
LoadedDirectory, MariaDbDatabase, MariaDbUser, NpmInstall, Owner, PhpFpmPool, Resource,
ServeCustom, ServePhp, ServeRedir, ServeService, ServeStatic, StoredDirectory,
LoadedDirectory, MariaDbDatabase, MariaDbUser, NpmInstall, Owner, PhpFpmPool, PostgresqlDatabase,
Resource, ServeCustom, ServePhp, ServeRedir, ServeService, ServeStatic, StoredDirectory,
SystemdSocketService, User, UserForDomain, WordpressPlugin, WordpressTranslation,
};
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> {
type Prerequisites = ();
fn locate(

7
src/resources/mod.rs

@ -200,6 +200,12 @@ impl<D> Resource for MariaDbUser<D> {
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)]
pub struct WordpressPlugin<P>(pub P, pub &'static str);
impl<P> Resource for WordpressPlugin<P> {
@ -288,6 +294,7 @@ default_resources!(
LoadedDirectory: LoadedDirectory<PathBuf>,
MariaDbDatabase: MariaDbDatabase<D>,
MariaDbUser: MariaDbUser<D>,
PostgresqlDatabase: PostgresqlDatabase<D>,
SystemdSocketService: SystemdSocketService<D, PathBuf>,
NpmInstall: NpmInstall<PathBuf>,
Owner: Owner<PathBuf>,

Loading…
Cancel
Save