path configuration file is verified at the start of execution
This commit is contained in:
@@ -10,9 +10,11 @@ namespace verify
|
|||||||
public:
|
public:
|
||||||
static void checkIcarus(const model::BinaryPath&);
|
static void checkIcarus(const model::BinaryPath&);
|
||||||
private:
|
private:
|
||||||
bool confirmConfigAuth(const model::BinaryPath&);
|
static bool confirmConfigAuth(const model::BinaryPath&);
|
||||||
bool confirmConfigDatabase(const model::BinaryPath&);
|
static bool confirmConfigDatabase(const model::BinaryPath&);
|
||||||
bool confirmConfigPaths(const model::BinaryPath&);
|
static bool confirmConfigPaths(const model::BinaryPath&);
|
||||||
|
|
||||||
|
static void failedConfirmation();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ std::string manager::DirectoryManager::retrievePathType(type::PathType pType)
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nlohmann::json manager::DirectoryManager::credentialConfigContent(const model::BinaryPath& bConf)
|
nlohmann::json manager::DirectoryManager::credentialConfigContent(const model::BinaryPath& bConf)
|
||||||
{
|
{
|
||||||
auto path = configPath(bConf);
|
auto path = configPath(bConf);
|
||||||
|
|||||||
@@ -1,25 +1,99 @@
|
|||||||
#include "verify/Initialization.h"
|
#include "verify/Initialization.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
|
#include "manager/DirectoryManager.h"
|
||||||
|
#include "type/PathType.h"
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
// verifies if the configuration settings are valid
|
// verifies if the configuration settings are valid
|
||||||
void verify::Initialization::checkIcarus(const model::BinaryPath& bConf)
|
void verify::Initialization::checkIcarus(const model::BinaryPath& bConf)
|
||||||
{
|
{
|
||||||
|
auto auth = confirmConfigAuth(bConf);
|
||||||
|
auto database = confirmConfigDatabase(bConf);
|
||||||
|
auto path = confirmConfigPaths(bConf);
|
||||||
|
|
||||||
|
if ((auth && database && path) == false) {
|
||||||
|
failedConfirmation();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "icarus check passed" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// verifies that the authorization settings are not the default values
|
// verifies that the authorization settings are not the default values
|
||||||
bool verify::Initialization::confirmConfigAuth(const model::BinaryPath& bConf)
|
bool verify::Initialization::confirmConfigAuth(const model::BinaryPath& bConf)
|
||||||
{
|
{
|
||||||
|
auto authConfig = manager::DirectoryManager::credentialConfigContent(bConf);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// verifies if database connectivity can be established
|
// verifies if database connectivity can be established
|
||||||
bool verify::Initialization::confirmConfigDatabase(const model::BinaryPath& bConf)
|
bool verify::Initialization::confirmConfigDatabase(const model::BinaryPath& bConf)
|
||||||
{
|
{
|
||||||
|
auto databaseConfig = manager::DirectoryManager::databaseConfigContent(bConf);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// verifies if the paths found in the config files exists
|
// verifies if the paths found in the config files exists
|
||||||
bool verify::Initialization::confirmConfigPaths(const model::BinaryPath& bConf)
|
bool verify::Initialization::confirmConfigPaths(const model::BinaryPath& bConf)
|
||||||
{
|
{
|
||||||
|
auto pathConfig = manager::DirectoryManager::pathConfigContent(bConf);
|
||||||
|
|
||||||
|
const auto rootMusicPath =
|
||||||
|
pathConfig
|
||||||
|
[manager::
|
||||||
|
DirectoryManager::
|
||||||
|
retrievePathType
|
||||||
|
(type::PathType::music)].get<std::string>();
|
||||||
|
const auto archiveRootPath =
|
||||||
|
pathConfig
|
||||||
|
[manager::
|
||||||
|
DirectoryManager::
|
||||||
|
retrievePathType
|
||||||
|
(type::PathType::archive)].get<std::string>();
|
||||||
|
const auto tempRootPath =
|
||||||
|
pathConfig
|
||||||
|
[manager::
|
||||||
|
DirectoryManager::
|
||||||
|
retrievePathType
|
||||||
|
(type::PathType::temp)].get<std::string>();
|
||||||
|
const auto coverRootPath =
|
||||||
|
pathConfig
|
||||||
|
[manager::
|
||||||
|
DirectoryManager::
|
||||||
|
retrievePathType
|
||||||
|
(type::PathType::coverArt)].get<std::string>();
|
||||||
|
|
||||||
|
if (!fs::exists(rootMusicPath)) {
|
||||||
|
std::cout << "root music path is not properly configured" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs::exists(archiveRootPath)) {
|
||||||
|
std::cout << "archive root path is not properly configured" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs::exists(tempRootPath)) {
|
||||||
|
std::cout << "temp root path is not properly configured" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs::exists(coverRootPath)) {
|
||||||
|
std::cout << "cover art root path is not properly configured" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// confirmation failed
|
||||||
|
void verify::Initialization::failedConfirmation()
|
||||||
|
{
|
||||||
|
std::cout << "configuration confirmation failed. check your settings" << std::endl;
|
||||||
|
std::exit(-1);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user