Skip to content
Snippets Groups Projects
Commit bbe029f2 authored by Steven Murray's avatar Steven Murray
Browse files

Added cta-catalogue-admin-user-create and cta-catalogue-admin-host-create

parent 31a9f138
No related branches found
Tags v4.4.0-1
No related merge requests found
Showing
with 969 additions and 0 deletions
......@@ -192,3 +192,25 @@ target_link_libraries (cta-database-poll
install (TARGETS cta-database-poll DESTINATION /usr/bin)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-database-poll.1cta DESTINATION /usr/share/man/man1)
add_executable(cta-catalogue-admin-user-create
CreateAdminUserCmd.cpp
CreateAdminUserCmdLineArgs.cpp
CreateAdminUserCmdMain.cpp)
target_link_libraries (cta-catalogue-admin-user-create
ctacatalogue)
install (TARGETS cta-catalogue-admin-user-create DESTINATION /usr/bin)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-catalogue-admin-user-create.1cta DESTINATION /usr/share/man/man1)
add_executable(cta-catalogue-admin-host-create
CreateAdminHostCmd.cpp
CreateAdminHostCmdLineArgs.cpp
CreateAdminHostCmdMain.cpp)
target_link_libraries (cta-catalogue-admin-host-create
ctacatalogue)
install (TARGETS cta-catalogue-admin-host-create DESTINATION /usr/bin)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-catalogue-admin-host-create.1cta DESTINATION /usr/share/man/man1)
......@@ -18,6 +18,8 @@
#include "catalogue/CmdLineTool.hpp"
#include <unistd.h>
namespace cta {
namespace catalogue {
......@@ -39,5 +41,32 @@ CmdLineTool::CmdLineTool(
CmdLineTool::~CmdLineTool() noexcept {
}
//------------------------------------------------------------------------------
// getUsername
//------------------------------------------------------------------------------
std::string CmdLineTool::getUsername() const {
char buf[256];
if(getlogin_r(buf, sizeof(buf))) {
return "UNKNOWN";
} else {
return buf;
}
}
//------------------------------------------------------------------------------
// getHostname
//------------------------------------------------------------------------------
std::string CmdLineTool::getHostname() const {
char buf[256];
if(gethostname(buf, sizeof(buf))) {
return "UNKNOWN";
} else {
buf[sizeof(buf) - 1] = '\0';
return buf;
}
}
} // namespace catalogue
} // namespace cta
......@@ -70,6 +70,20 @@ protected:
*/
std::ostream &m_err;
/**
* Returns the name of the user running the command-line tool.
*
* @return The name of the user running the command-line tool.
*/
std::string getUsername() const;
/**
* Returns the name of the host on which the command-line tool is running.
*
* @return The name of the host on which the command-line tool is running.
*/
std::string getHostname() const;
}; // class CmdLineTool
} // namespace catalogue
......
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/CatalogueFactory.hpp"
#include "catalogue/CreateAdminHostCmd.hpp"
#include "catalogue/CreateAdminHostCmdLineArgs.hpp"
#include "common/exception/Exception.hpp"
#include "rdbms/ConnFactoryFactory.hpp"
namespace cta {
namespace catalogue {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
CreateAdminHostCmd::CreateAdminHostCmd(
std::istream &inStream,
std::ostream &outStream,
std::ostream &errStream):
CmdLineTool(inStream, outStream, errStream) {
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
CreateAdminHostCmd::~CreateAdminHostCmd() noexcept {
}
//------------------------------------------------------------------------------
// exceptionThrowingMain
//------------------------------------------------------------------------------
int CreateAdminHostCmd::exceptionThrowingMain(const int argc, char *const *const argv) {
const CreateAdminHostCmdLineArgs cmdLineArgs(argc, argv);
if(cmdLineArgs.help) {
CreateAdminHostCmdLineArgs::printUsage(m_out);
return 0;
}
const rdbms::Login dbLogin = rdbms::Login::parseFile(cmdLineArgs.dbConfigPath);
const uint64_t nbDbConns = 1;
auto catalogue = CatalogueFactory::create(dbLogin, nbDbConns);
const common::dataStructures::SecurityIdentity adminRunningCommand(getUsername(), getHostname());
catalogue->createAdminHost(adminRunningCommand, cmdLineArgs.adminHostname, cmdLineArgs.comment);
return 0;
}
} // namespace catalogue
} // namespace cta
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "catalogue/Catalogue.hpp"
#include "catalogue/CmdLineTool.hpp"
namespace cta {
namespace catalogue {
/**
* Command-line tool that creates an admin host.
*/
class CreateAdminHostCmd: public CmdLineTool {
public:
/**
* Constructor.
*
* @param inStream Standard input stream.
* @param outStream Standard output stream.
* @param errStream Standard error stream.
*/
CreateAdminHostCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream);
/**
* Destructor.
*/
~CreateAdminHostCmd() noexcept;
/**
* An exception throwing version of main().
*
* @param argc The number of command-line arguments including the program name.
* @param argv The command-line arguments.
* @return The exit value of the program.
*/
int exceptionThrowingMain(const int argc, char *const *const argv);
}; // class CreateAdminHostCmd
} // namespace catalogue
} // namespace cta
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/CreateAdminHostCmdLineArgs.hpp"
#include "common/exception/UserError.hpp"
#include <getopt.h>
#include <ostream>
namespace cta {
namespace catalogue {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
CreateAdminHostCmdLineArgs::CreateAdminHostCmdLineArgs(const int argc, char *const *const argv):
help(false) {
static struct option longopts[] = {
{"comment" , 0, NULL, 'c'},
{"help" , 0, NULL, 'h'},
{"hostname" , 0, NULL, 'n'},
{NULL , 0, NULL, 0}
};
// Prevent getopt() from printing an error message if it does not recognize
// an option character
opterr = 0;
int opt = 0;
while((opt = getopt_long(argc, argv, ":c:hn:", longopts, NULL)) != -1) {
switch(opt) {
case 'c':
comment = optarg;
break;
case 'h':
help = true;
break;
case 'n':
adminHostname = optarg;
break;
case ':': // Missing parameter
{
exception::UserError ex;
ex.getMessage() << "The -" << (char)opt << " option requires a parameter";
throw ex;
}
case '?': // Unknown option
{
exception::UserError ex;
if(0 == optopt) {
ex.getMessage() << "Unknown command-line option";
} else {
ex.getMessage() << "Unknown command-line option: -" << (char)optopt;
}
throw ex;
}
default:
{
exception::UserError ex;
ex.getMessage() <<
"getopt_long returned the following unknown value: 0x" <<
std::hex << (int)opt;
throw ex;
}
} // switch(opt)
} // while getopt_long()
// There is no need to continue parsing when the help option is set
if(help) {
return;
}
if(adminHostname.empty()) {
throw exception::Exception("The hostname option must be specified with a non-empty string");
}
if(comment.empty()) {
throw exception::Exception("The comment option must be specified with a non-empty string");
}
// Calculate the number of non-option ARGV-elements
const int nbArgs = argc - optind;
// Check the number of arguments
if(nbArgs != 1) {
exception::UserError ex;
ex.getMessage() << "Wrong number of command-line arguments: excepted=1 actual=" << (argc - 1);
throw ex;
}
dbConfigPath = argv[optind];
}
//------------------------------------------------------------------------------
// printUsage
//------------------------------------------------------------------------------
void CreateAdminHostCmdLineArgs::printUsage(std::ostream &os) {
os <<
"Usage:" << std::endl <<
" cta-catalogue-admin-host-create databaseConnectionFile -n <hostname> -c <comment> [-h]" << std::endl <<
"Where:" << std::endl <<
" databaseConnectionFile" << std::endl <<
" The path to the file containing the connection details of the CTA" << std::endl <<
" catalogue database" << std::endl <<
"Options:" << std::endl <<
" -n,--hostname <hostname>" << std::endl <<
" The name of the admin host to be created" << std::endl <<
" -c,--comment <comment>" << std::endl <<
" Comment to describe the creation of the admin host" << std::endl <<
" -h,--help" << std::endl <<
" Prints this usage message" << std::endl <<
"" << std::endl;;
}
} // namespace catalogue
} // namespace cta
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <string>
namespace cta {
namespace catalogue {
/**
* Structure to store the command-line arguments of the command-line tool
* named cta-catalogue-admin-host-create
*/
struct CreateAdminHostCmdLineArgs {
/**
* True if the usage message should be printed.
*/
bool help;
/**
* Path to the file containing the connection details of the catalogue
* database.
*/
std::string dbConfigPath;
/**
* The name of the admin host to be created in the catalogue database.
*/
std::string adminHostname;
/**
* The optional comment describing the creation of the admin host.
*/
std::string comment;
/**
* Constructor that parses the specified command-line arguments.
*
* @param argc The number of command-line arguments including the name of the
* executable.
* @param argv The vector of command-line arguments.
*/
CreateAdminHostCmdLineArgs(const int argc, char *const *const argv);
/**
* Prints the usage message of the command-line tool.
*
* @param os The output stream to which the usage message is to be printed.
*/
static void printUsage(std::ostream &os);
};
} // namespace catalogue
} // namespace cta
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/CreateAdminHostCmd.hpp"
#include "catalogue/CreateAdminHostCmdLineArgs.hpp"
#include "common/exception/Exception.hpp"
#include "common/exception/UserError.hpp"
#include <iostream>
/**
* An exception throwing version of main().
*
* @param argc The number of command-line arguments including the program name.
* @param argv The command-line arguments.
* @return The exit value of the program.
*/
static int exceptionThrowingMain(const int argc, char *const *const argv);
//------------------------------------------------------------------------------
// main
//------------------------------------------------------------------------------
int main(const int argc, char *const *const argv) {
using namespace cta;
bool userError = false;
std::string errorMessage;
try {
return exceptionThrowingMain(argc, argv);
} catch(exception::UserError &ue) {
errorMessage = ue.getMessage().str();
userError = true;
} catch(exception::Exception &ex) {
errorMessage = ex.getMessage().str();
} catch(std::exception &se) {
errorMessage = se.what();
} catch(...) {
errorMessage = "An unknown exception was thrown";
}
// Reaching this point means the command has failed, an exception was throw
// and errorMessage has been set accordingly
std::cerr << "Aborting: " << errorMessage << std::endl;
if(userError) {
std::cerr << std::endl;
catalogue::CreateAdminHostCmdLineArgs::printUsage(std::cerr);
}
return 1;
}
//------------------------------------------------------------------------------
// exceptionThrowingMain
//------------------------------------------------------------------------------
static int exceptionThrowingMain(const int argc, char *const *const argv) {
using namespace cta;
catalogue::CreateAdminHostCmd cmd(std::cin, std::cout, std::cerr);
return cmd.exceptionThrowingMain(argc, argv);
}
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/CatalogueFactory.hpp"
#include "catalogue/CreateAdminUserCmd.hpp"
#include "catalogue/CreateAdminUserCmdLineArgs.hpp"
#include "common/exception/Exception.hpp"
#include "rdbms/ConnFactoryFactory.hpp"
namespace cta {
namespace catalogue {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
CreateAdminUserCmd::CreateAdminUserCmd(
std::istream &inStream,
std::ostream &outStream,
std::ostream &errStream):
CmdLineTool(inStream, outStream, errStream) {
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
CreateAdminUserCmd::~CreateAdminUserCmd() noexcept {
}
//------------------------------------------------------------------------------
// exceptionThrowingMain
//------------------------------------------------------------------------------
int CreateAdminUserCmd::exceptionThrowingMain(const int argc, char *const *const argv) {
const CreateAdminUserCmdLineArgs cmdLineArgs(argc, argv);
if(cmdLineArgs.help) {
CreateAdminUserCmdLineArgs::printUsage(m_out);
return 0;
}
const rdbms::Login dbLogin = rdbms::Login::parseFile(cmdLineArgs.dbConfigPath);
const uint64_t nbDbConns = 1;
auto catalogue = CatalogueFactory::create(dbLogin, nbDbConns);
const common::dataStructures::SecurityIdentity adminRunningCommand(getUsername(), getHostname());
catalogue->createAdminUser(adminRunningCommand, cmdLineArgs.adminUsername, cmdLineArgs.comment);
return 0;
}
} // namespace catalogue
} // namespace cta
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "catalogue/Catalogue.hpp"
#include "catalogue/CmdLineTool.hpp"
namespace cta {
namespace catalogue {
/**
* Command-line tool that creates an admin user.
*/
class CreateAdminUserCmd: public CmdLineTool {
public:
/**
* Constructor.
*
* @param inStream Standard input stream.
* @param outStream Standard output stream.
* @param errStream Standard error stream.
*/
CreateAdminUserCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream);
/**
* Destructor.
*/
~CreateAdminUserCmd() noexcept;
/**
* An exception throwing version of main().
*
* @param argc The number of command-line arguments including the program name.
* @param argv The command-line arguments.
* @return The exit value of the program.
*/
int exceptionThrowingMain(const int argc, char *const *const argv);
}; // class CreateAdminUserCmd
} // namespace catalogue
} // namespace cta
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/CreateAdminUserCmdLineArgs.hpp"
#include "common/exception/UserError.hpp"
#include <getopt.h>
#include <ostream>
namespace cta {
namespace catalogue {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
CreateAdminUserCmdLineArgs::CreateAdminUserCmdLineArgs(const int argc, char *const *const argv):
help(false) {
static struct option longopts[] = {
{"comment" , 0, NULL, 'c'},
{"help" , 0, NULL, 'h'},
{"username" , 0, NULL, 'u'},
{NULL , 0, NULL, 0}
};
// Prevent getopt() from printing an error message if it does not recognize
// an option character
opterr = 0;
int opt = 0;
while((opt = getopt_long(argc, argv, ":c:hu:", longopts, NULL)) != -1) {
switch(opt) {
case 'c':
comment = optarg;
break;
case 'h':
help = true;
break;
case 'u':
adminUsername = optarg;
break;
case ':': // Missing parameter
{
exception::UserError ex;
ex.getMessage() << "The -" << (char)opt << " option requires a parameter";
throw ex;
}
case '?': // Unknown option
{
exception::UserError ex;
if(0 == optopt) {
ex.getMessage() << "Unknown command-line option";
} else {
ex.getMessage() << "Unknown command-line option: -" << (char)optopt;
}
throw ex;
}
default:
{
exception::UserError ex;
ex.getMessage() <<
"getopt_long returned the following unknown value: 0x" <<
std::hex << (int)opt;
throw ex;
}
} // switch(opt)
} // while getopt_long()
// There is no need to continue parsing when the help option is set
if(help) {
return;
}
if(adminUsername.empty()) {
throw exception::Exception("The username option must be specified with a non-empty string");
}
if(comment.empty()) {
throw exception::Exception("The comment option must be specified with a non-empty string");
}
// Calculate the number of non-option ARGV-elements
const int nbArgs = argc - optind;
// Check the number of arguments
if(nbArgs != 1) {
exception::UserError ex;
ex.getMessage() << "Wrong number of command-line arguments: excepted=1 actual=" << (argc - 1);
throw ex;
}
dbConfigPath = argv[optind];
}
//------------------------------------------------------------------------------
// printUsage
//------------------------------------------------------------------------------
void CreateAdminUserCmdLineArgs::printUsage(std::ostream &os) {
os <<
"Usage:" << std::endl <<
" cta-catalogue-admin-user-create databaseConnectionFile -u <username> -c <comment> [-h]" << std::endl <<
"Where:" << std::endl <<
" databaseConnectionFile" << std::endl <<
" The path to the file containing the connection details of the CTA" << std::endl <<
" catalogue database" << std::endl <<
"Options:" << std::endl <<
" -u,--username <username>" << std::endl <<
" The name of the admin user to be created" << std::endl <<
" -c,--comment <comment>" << std::endl <<
" Comment to describe the creation of the admin user" << std::endl <<
" -h,--help" << std::endl <<
" Prints this usage message" << std::endl <<
"" << std::endl;;
}
} // namespace catalogue
} // namespace cta
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include <string>
namespace cta {
namespace catalogue {
/**
* Structure to store the command-line arguments of the command-line tool
* named cta-catalogue-admin-user-create
*/
struct CreateAdminUserCmdLineArgs {
/**
* True if the usage message should be printed.
*/
bool help;
/**
* Path to the file containing the connection details of the catalogue
* database.
*/
std::string dbConfigPath;
/**
* The name of the admin user to be created in the catalogue database.
*/
std::string adminUsername;
/**
* The optional comment describing the creation of the admin user.
*/
std::string comment;
/**
* Constructor that parses the specified command-line arguments.
*
* @param argc The number of command-line arguments including the name of the
* executable.
* @param argv The vector of command-line arguments.
*/
CreateAdminUserCmdLineArgs(const int argc, char *const *const argv);
/**
* Prints the usage message of the command-line tool.
*
* @param os The output stream to which the usage message is to be printed.
*/
static void printUsage(std::ostream &os);
};
} // namespace catalogue
} // namespace cta
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "catalogue/CreateAdminUserCmd.hpp"
#include "catalogue/CreateAdminUserCmdLineArgs.hpp"
#include "common/exception/Exception.hpp"
#include "common/exception/UserError.hpp"
#include <iostream>
/**
* An exception throwing version of main().
*
* @param argc The number of command-line arguments including the program name.
* @param argv The command-line arguments.
* @return The exit value of the program.
*/
static int exceptionThrowingMain(const int argc, char *const *const argv);
//------------------------------------------------------------------------------
// main
//------------------------------------------------------------------------------
int main(const int argc, char *const *const argv) {
using namespace cta;
bool userError = false;
std::string errorMessage;
try {
return exceptionThrowingMain(argc, argv);
} catch(exception::UserError &ue) {
errorMessage = ue.getMessage().str();
userError = true;
} catch(exception::Exception &ex) {
errorMessage = ex.getMessage().str();
} catch(std::exception &se) {
errorMessage = se.what();
} catch(...) {
errorMessage = "An unknown exception was thrown";
}
// Reaching this point means the command has failed, an exception was throw
// and errorMessage has been set accordingly
std::cerr << "Aborting: " << errorMessage << std::endl;
if(userError) {
std::cerr << std::endl;
catalogue::CreateAdminUserCmdLineArgs::printUsage(std::cerr);
}
return 1;
}
//------------------------------------------------------------------------------
// exceptionThrowingMain
//------------------------------------------------------------------------------
static int exceptionThrowingMain(const int argc, char *const *const argv) {
using namespace cta;
catalogue::CreateAdminUserCmd cmd(std::cin, std::cout, std::cerr);
return cmd.exceptionThrowingMain(argc, argv);
}
.\" The CERN Tape Archive (CTA) project
.\" Copyright (C) 2015 CERN
.\"
.\" 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 3 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, see <http://www.gnu.org/licenses/>.
.TH CTA-CATALOGUE-ADMIN-HOST-CREATE 1CTA "December 2016" CTA CTA
.SH NAME
cta-catalogue-admin-host-create \- Create a CTA admin host
.SH SYNOPSIS
.BI "cta-catalogue-admin-host-create databaseConnectionFile -n <hostname> -c <comment> [-h]"
.SH DESCRIPTION
\fBcta-catalogue-admin-host-create\fP is a command-line tool that creates an
admin host in the catalogue database. \fBcta-catalogue-admin-host-create\fP
connects directly to the catalogue database as opposed to the cta command-line
tool that connects to the CTA front end. \fBcta-catalogue-admin-host-create\fP
can therefore be used to bootstrap the creation of CTA admin hosts.
.P
.SH ARGUMENTS
.TP
\fBdatabaseConnectionFile
The path to the configuration file containing the connection details of the
CTA catalogue database.
.SH OPTIONS
.TP
\fB\-n, \-\-hostname <hostname>
The name of the admin host to be created.
.TP
\fB\-c, \-\-comment <comment>
Comment describing the creation of the admin host.
.TP
\fB\-h, \-\-help
Prints the usage message.
.SH RETURN VALUE
Zero on success and non-zero on failure.
.SH EXAMPLES
cta-catalogue-admin-host-create /etc/cta/cta_catalogue_db.conf -u ctaadminhost -c "The CTA admin host"
.SH AUTHOR
\fBCTA\fP Team
.\" The CERN Tape Archive (CTA) project
.\" Copyright (C) 2015 CERN
.\"
.\" 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 3 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, see <http://www.gnu.org/licenses/>.
.TH CTA-CATALOGUE-ADMIN-USER-CREATE 1CTA "December 2016" CTA CTA
.SH NAME
cta-catalogue-admin-user-create \- Create a CTA admin user
.SH SYNOPSIS
.BI "cta-catalogue-admin-user-create databaseConnectionFile -u <username> -c <comment> [-h]"
.SH DESCRIPTION
\fBcta-catalogue-admin-user-create\fP is a command-line tool that creates an
admin user in the catalogue database. \fBcta-catalogue-admin-user-create\fP
connects directly to the catalogue database as opposed to the cta command-line
tool that connects to the CTA front end. \fBcta-catalogue-admin-user-create\fP
can therefore be used to bootstrap the creation of CTA admin users.
.P
.SH ARGUMENTS
.TP
\fBdatabaseConnectionFile
The path to the configuration file containing the connection details of the
CTA catalogue database.
.SH OPTIONS
.TP
\fB\-u, \-\-username <username>
The name of the admin user to be created.
.TP
\fB\-c, \-\-comment <comment>
Comment describing the creation of the admin user.
.TP
\fB\-h, \-\-help
Prints the usage message.
.SH RETURN VALUE
Zero on success and non-zero on failure.
.SH EXAMPLES
cta-catalogue-admin-user-create /etc/cta/cta_catalogue_db.conf -u ctaadmin -c "The CTA admin account"
.SH AUTHOR
\fBCTA\fP Team
......@@ -238,6 +238,8 @@ Group: Application/CTA
CERN Tape Archive:
Scripts and utilities to faciliate working with the CTA catalogue
%files -n cta-catalogueutils
%attr(0755,root,root) %{_bindir}/cta-catalogue-admin-user-create
%attr(0755,root,root) %{_bindir}/cta-catalogue-admin-host-create
%attr(0755,root,root) %{_bindir}/cta-catalogue-delete-all-data
%attr(0755,root,root) %{_bindir}/cta-catalogue-schema-create
%attr(0755,root,root) %{_bindir}/cta-catalogue-schema-drop
......@@ -245,6 +247,8 @@ Scripts and utilities to faciliate working with the CTA catalogue
%attr(0755,root,root) %{_bindir}/cta-catalogue-schema-status
%attr(0755,root,root) %{_bindir}/cta-catalogue-schema-unlock
%attr(0755,root,root) %{_bindir}/cta-database-poll
%attr(0644,root,bin) %doc /usr/share/man/man1/cta-catalogue-admin-host-create.1cta.gz
%attr(0644,root,bin) %doc /usr/share/man/man1/cta-catalogue-admin-user-create.1cta.gz
%attr(0644,root,bin) %doc /usr/share/man/man1/cta-catalogue-delete-all-data.1cta.gz
%attr(0644,root,bin) %doc /usr/share/man/man1/cta-catalogue-schema-create.1cta.gz
%attr(0644,root,bin) %doc /usr/share/man/man1/cta-catalogue-schema-drop.1cta.gz
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment