/************************************************************************* * * Copyright (c) 2023 Fabian Posch * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * ************************************************************************** */ #ifndef __CLI_UTIL_H__ #define __CLI_UTIL_H__ #include #include #include "db_client.hpp" #define POSTGRES_DEFAULT_PORT 5432 // environment variables used by the database module of the argument parser #define SERVER_ADDR_ENV "ACT_DEPLOY_SERVER_ADDR" #define SERVER_PORT_ENV "ACT_DEPLOY_SERVER_PORT" #define SERVER_USER_ENV "ACT_DEPLOY_SERVER_USER" #define SERVER_PWD_ENV "ACT_DEPLOY_SERVER_PWD" #define SERVER_DBASE_ENV "ACT_DEPLOY_SERVER_DBASE" /** * @brief Parse database credentials from arguments or environment * * Parses the database options common between the different commands. No command line overrides were given, * the data is loaded from environment variables given externally through macros. These macros are: * * - SERVER_ADDR_ENV: Environment variable containing the address of the Postgresql database server * - SERVER_PORT_ENV: Variable containing the port of the Postgresql database server * - SERVER_USER_ENV: Variable containing the database user * - SERVER_PWD_ENV: Variable containing the database password * - SERVER_DBASE_ENV: Variable containing the database name * * @param arguments Argument list given to the program * @return db_credentials_t Structure containing the database credentials * * @throw std::invalid_argument Thrown if the server name was set by neither the environment nor an override argument * @throw std::invalid_argument Thrown if the server port was set by neither the environment nor an override argument * @throw std::invalid_argument Thrown if the given port is invalid * @throw std::invalid_argument Thrown if the database user was set by neither the environment nor an override argument * @throw std::invalid_argument Thrown if the database password was set by neither the environment nor an override argument * @throw std::invalid_argument Thrown if the database name was set by neither the environment nor an override argument */ //db::db_credentials_t get_db_cred (arg_list& arguments); void get_db_cred_env (db::db_credentials_t& db_cred); #endif