diff --git a/src/EncryptionModule.cpp b/src/EncryptionModule.cpp new file mode 100644 index 0000000..540457e --- /dev/null +++ b/src/EncryptionModule.cpp @@ -0,0 +1,34 @@ +// deployer EncryptionModule implementation +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#include "EncryptionModule.h" +using namespace std; + +//constructor +EncryptionModule::EncryptionModule(){ + name="Let's Encrypt"; +} + +//destructor inline + +//public methods +int EncryptionModule::Prepare () +{ + return 0; +} + +int EncryptionModule::Deploy (string serviceUsername) +{ + return 0; +} + +int EncryptionModule::Remove(string serviceUsername) +{ + return 0; +} + +int EncryptionModule::Clean () +{ + return 0; +} \ No newline at end of file diff --git a/src/EncryptionModule.h b/src/EncryptionModule.h new file mode 100644 index 0000000..b805b4b --- /dev/null +++ b/src/EncryptionModule.h @@ -0,0 +1,20 @@ +// deployer EncryptionModule header +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#if !defined(ENCRYPTIONMODULE_H) +#define ENCRYPTIONMODULE_H + +#include "Module.h" + +class EncryptionModule : public Module +{ + public: + EncryptionModule(); + ~EncryptionModule(){} //inline + int Prepare (); + int Deploy (string serviceUsername); + int Remove(string serviceUsername); + int Clean (); +}; +#endif \ No newline at end of file diff --git a/src/NginxModule.cpp b/src/NginxModule.cpp new file mode 100644 index 0000000..0d4c1b4 --- /dev/null +++ b/src/NginxModule.cpp @@ -0,0 +1,34 @@ +// deployer NginxModule implementation +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#include "NginxModule.h" +using namespace std; + +//constructor +NginxModule::NginxModule(){ + name="Let's Encrypt"; +} + +//destructor inline + +//public methods +int NginxModule::Prepare () +{ + return 0; +} + +int NginxModule::Deploy (string serviceUsername) +{ + return 0; +} + +int NginxModule::Remove(string serviceUsername) +{ + return 0; +} + +int NginxModule::Clean () +{ + return 0; +} \ No newline at end of file diff --git a/src/NginxModule.h b/src/NginxModule.h new file mode 100644 index 0000000..abfae50 --- /dev/null +++ b/src/NginxModule.h @@ -0,0 +1,23 @@ +// deployer NginxModule header +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#if !defined(NGINXMODULE_H) +#define NGINXMODULE_H + +#include "Module.h" + +class NginxModule : public Module +{ + public: + NginxModule();//inline + ~NginxModule(){} //inline + int Prepare (); + int Deploy (string serviceUsername); + int Remove(string serviceUsername); + int Clean (); + private: + int removeContainersCreatedByDockerCompose(); + int removeContainersWithServiceName (string serviceUsename); +}; +#endif \ No newline at end of file diff --git a/src/WireguardModule.cpp b/src/WireguardModule.cpp new file mode 100644 index 0000000..7f24944 --- /dev/null +++ b/src/WireguardModule.cpp @@ -0,0 +1,34 @@ +// deployer WireguardModule implementation +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#include "WireguardModule.h" +using namespace std; + +//constructor +WireguardModule::WireguardModule(){ + name="Let's Encrypt"; +} + +//destructor inline + +//public methods +int WireguardModule::Prepare () +{ + return 0; +} + +int WireguardModule::Deploy (string serviceUsername) +{ + return 0; +} + +int WireguardModule::Remove(string serviceUsername) +{ + return 0; +} + +int WireguardModule::Clean () +{ + return 0; +} \ No newline at end of file diff --git a/src/WireguardModule.h b/src/WireguardModule.h new file mode 100644 index 0000000..26e2d5a --- /dev/null +++ b/src/WireguardModule.h @@ -0,0 +1,20 @@ +// deployer WireguardModule header +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#if !defined(WIREGUARDMODULE_H) +#define WIREGUARDMODULE_H + +#include "Module.h" + +class WireguardModule : public Module +{ + public: + WireguardModule(); + ~WireguardModule(){} //inline + int Prepare (); + int Deploy (string serviceUsername); + int Remove(string serviceUsername); + int Clean (); +}; +#endif \ No newline at end of file diff --git a/test/IntegrationTests/main.cpp b/test/IntegrationTests/main.cpp new file mode 100644 index 0000000..8710026 --- /dev/null +++ b/test/IntegrationTests/main.cpp @@ -0,0 +1,77 @@ +// deployer IntegrationTests main +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#include +#include "BashManager.h" + +using namespace std; + +void Help() +{ + cout << "blabla" << endl; +} + +//tests +void environmentTest() +{ + cout << "Test of the environment setup." << endl; +} + +void bashTest() +{ + cout << "Test of BashModule" << endl; +} + +void dockerTest() +{ + cout << "Test of DockerModule" << endl; +} + +void nginxTest() +{ + cout << "Test of Nginx module" << endl; +} + +void wireguardTest() +{ + cout << "Test of WireguardModule" << endl; +} + +void encryptionTest() +{ + cout << "Test of EncryptionModule" << endl; +} + +int main(int argc, char **argv) +{ + if(argc!=2){ + cerr << "Invalid number of arguments." << endl; + } else{ + BashManager::Execute("./deployer deploy all"); + string action=argv[1]; + if (action=="environment"){ + environmentTest(); + } else if (action=="bash"){ + bashTest(); + } else if (action=="docker"){ + dockerTest(); + } else if (action=="nginx"){ + nginxTest(); + } else if (action=="wireguard"){ + wireguardTest(); + } else if (action=="encryption"){ + encryptionTest(); + } else if (action=="all"){ + environmentTest(); + bashTest(); + dockerTest(); + nginxTest(); + wireguardTest(); + encryptionTest(); + } else { + cerr << "Unknown argument." << endl; + Help(); + } + } +} \ No newline at end of file diff --git a/test/IntegrationTests/src/BashManager.cpp b/test/IntegrationTests/src/BashManager.cpp new file mode 100644 index 0000000..50933b7 --- /dev/null +++ b/test/IntegrationTests/src/BashManager.cpp @@ -0,0 +1,38 @@ +// deployer BashManager implementation +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#include +#include "BashManager.h" + +int BashManager::Execute(string command) +{ + FILE * p = popen(command.c_str(),"r"); + if( p == NULL) + { + cerr << "Error executing " << command << endl; + return -1; + } + pclose(p); + return 0; +} + +string BashManager::ExecuteAndReadResult(string command) +{ + string result=""; + char lineBuffer [4095]={0}; //4095 is the maximum length of a shell line + FILE * p = popen(command.c_str(),"r"); + if( p == nullptr) + { + cerr << "Error executing "<< command << endl; + } + while(fgets(lineBuffer,sizeof(lineBuffer),p)){ + result += lineBuffer; + //removing newline character + if (!result.empty() && result[result.length()-1] == '\n') { + result.erase(result.length()-1); + } + } + pclose(p); + return result; +} diff --git a/test/IntegrationTests/src/BashManager.h b/test/IntegrationTests/src/BashManager.h new file mode 100644 index 0000000..e265a09 --- /dev/null +++ b/test/IntegrationTests/src/BashManager.h @@ -0,0 +1,19 @@ +// deployer BashManager header +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#if !defined(BASHMANAGER_H) +#define BASHMANAGER_H + +#include +#include + +using namespace std; +class BashManager +{ + public: + static string ExecuteAndReadResult(string command); + static int Execute(string command); +}; + +#endif \ No newline at end of file diff --git a/test/IntegrationTests/src/Makefile b/test/IntegrationTests/src/Makefile new file mode 100644 index 0000000..fe82774 --- /dev/null +++ b/test/IntegrationTests/src/Makefile @@ -0,0 +1,24 @@ +ECHO = @echo +CP=@cp +GCC = g++ +RM = @rm -f +CCFLAGS = -c -O3 -g -std=c++20 -pedantic -Wall +SRC = $(wildcard *.cpp) +BIN = ../bin +EXE = integrationTests +OBJECTS = $(patsubst %.cpp,$(BIN)/%.o,$(SRC)) +LIBRARIES = + +$(EXE) : $(OBJECTS) + $(ECHO) "-Linking $(EXE)-" + $(GCC) -o $@ $^ $(LIBRARIES) + $(CP) $(EXE) ../../../testenv + +$(BIN)/%.o:%.cpp + $(ECHO) "-Compilation $<- " + $(GCC) $(CCFLAGS) -o $@ $< + +.PHONY: clean +clean: + $(ECHO) "-Cleaning-" + $(RM) $(OBJECTS) $(EXE) \ No newline at end of file diff --git a/test/IntegrationTests/src/integrationTests b/test/IntegrationTests/src/integrationTests new file mode 100755 index 0000000..21732d6 Binary files /dev/null and b/test/IntegrationTests/src/integrationTests differ diff --git a/test/IntegrationTests/src/main.cpp b/test/IntegrationTests/src/main.cpp new file mode 100644 index 0000000..8710026 --- /dev/null +++ b/test/IntegrationTests/src/main.cpp @@ -0,0 +1,77 @@ +// deployer IntegrationTests main +// Copyright (C) 2024 Jean-Cloud +// GNU General Public License v3 + +#include +#include "BashManager.h" + +using namespace std; + +void Help() +{ + cout << "blabla" << endl; +} + +//tests +void environmentTest() +{ + cout << "Test of the environment setup." << endl; +} + +void bashTest() +{ + cout << "Test of BashModule" << endl; +} + +void dockerTest() +{ + cout << "Test of DockerModule" << endl; +} + +void nginxTest() +{ + cout << "Test of Nginx module" << endl; +} + +void wireguardTest() +{ + cout << "Test of WireguardModule" << endl; +} + +void encryptionTest() +{ + cout << "Test of EncryptionModule" << endl; +} + +int main(int argc, char **argv) +{ + if(argc!=2){ + cerr << "Invalid number of arguments." << endl; + } else{ + BashManager::Execute("./deployer deploy all"); + string action=argv[1]; + if (action=="environment"){ + environmentTest(); + } else if (action=="bash"){ + bashTest(); + } else if (action=="docker"){ + dockerTest(); + } else if (action=="nginx"){ + nginxTest(); + } else if (action=="wireguard"){ + wireguardTest(); + } else if (action=="encryption"){ + encryptionTest(); + } else if (action=="all"){ + environmentTest(); + bashTest(); + dockerTest(); + nginxTest(); + wireguardTest(); + encryptionTest(); + } else { + cerr << "Unknown argument." << endl; + Help(); + } + } +} \ No newline at end of file diff --git a/test/IntegrationTests/testenv b/test/IntegrationTests/testenv new file mode 100755 index 0000000..7b85bcc Binary files /dev/null and b/test/IntegrationTests/testenv differ diff --git a/testenv/integrationTests b/testenv/integrationTests new file mode 100755 index 0000000..21732d6 Binary files /dev/null and b/testenv/integrationTests differ