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

Implemented RdbmsCatalogue::modifyTapeEncryptionKey()

parent c04dc7e6
No related branches found
No related tags found
No related merge requests found
......@@ -2417,6 +2417,91 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeCapacityInBytes) {
}
}
TEST_P(cta_catalogue_CatalogueTest, modifyTapeEncryptionKey) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getTapes().empty());
const std::string vid = "vid";
const std::string logicalLibraryName = "logical_library_name";
const std::string tapePoolName = "tape_pool_name";
const std::string encryptionKey = "encryption_key";
const uint64_t capacityInBytes = (uint64_t)10 * 1000 * 1000 * 1000 * 1000;
const bool disabledValue = true;
const bool fullValue = false;
const std::string comment = "Create tape";
m_catalogue->createLogicalLibrary(m_cliSI, logicalLibraryName, "Create logical library");
m_catalogue->createTapePool(m_cliSI, tapePoolName, 2, true, "Create tape pool");
m_catalogue->createTape(m_cliSI, vid, logicalLibraryName, tapePoolName, encryptionKey, capacityInBytes, disabledValue,
fullValue, comment);
{
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
ASSERT_EQ(1, tapes.size());
const common::dataStructures::Tape tape = tapes.front();
ASSERT_EQ(vid, tape.vid);
ASSERT_EQ(logicalLibraryName, tape.logicalLibraryName);
ASSERT_EQ(tapePoolName, tape.tapePoolName);
ASSERT_EQ(encryptionKey, tape.encryptionKey);
ASSERT_EQ(capacityInBytes, tape.capacityInBytes);
ASSERT_TRUE(disabledValue == tape.disabled);
ASSERT_TRUE(fullValue == tape.full);
ASSERT_EQ(comment, tape.comment);
ASSERT_FALSE(tape.labelLog);
ASSERT_FALSE(tape.lastReadLog);
ASSERT_FALSE(tape.lastWriteLog);
const common::dataStructures::EntryLog creationLog = tape.creationLog;
ASSERT_EQ(m_cliSI.username, creationLog.username);
ASSERT_EQ(m_cliSI.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog = tape.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
const std::string modifiedEncryptionKey = "modified_encryption_key";
m_catalogue->modifyTapeEncryptionKey(m_cliSI, vid, modifiedEncryptionKey);
{
const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
ASSERT_EQ(1, tapes.size());
const common::dataStructures::Tape tape = tapes.front();
ASSERT_EQ(vid, tape.vid);
ASSERT_EQ(logicalLibraryName, tape.logicalLibraryName);
ASSERT_EQ(tapePoolName, tape.tapePoolName);
ASSERT_EQ(modifiedEncryptionKey, tape.encryptionKey);
ASSERT_EQ(capacityInBytes, tape.capacityInBytes);
ASSERT_TRUE(disabledValue == tape.disabled);
ASSERT_TRUE(fullValue == tape.full);
ASSERT_EQ(comment, tape.comment);
ASSERT_FALSE(tape.labelLog);
ASSERT_FALSE(tape.lastReadLog);
ASSERT_FALSE(tape.lastWriteLog);
const common::dataStructures::EntryLog creationLog = tape.creationLog;
ASSERT_EQ(m_cliSI.username, creationLog.username);
ASSERT_EQ(m_cliSI.host, creationLog.host);
}
}
TEST_P(cta_catalogue_CatalogueTest, modifyTapeEncryptionKey_nonExistentTape) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getTapes().empty());
const std::string vid = "vid";
const std::string encryptionKey = "encryption_key";
ASSERT_THROW(m_catalogue->modifyTapeEncryptionKey(m_cliSI, vid, encryptionKey), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, modifyTapeCapacityInBytes_nonExistentTape) {
using namespace cta;
......
......@@ -1877,8 +1877,35 @@ void RdbmsCatalogue::modifyTapeCapacityInBytes(const common::dataStructures::Sec
//------------------------------------------------------------------------------
// modifyTapeEncryptionKey
//------------------------------------------------------------------------------
void RdbmsCatalogue::modifyTapeEncryptionKey(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const std::string &encryptionKey) {
throw exception::Exception(std::string(__FUNCTION__) + " not implemented");
void RdbmsCatalogue::modifyTapeEncryptionKey(const common::dataStructures::SecurityIdentity &cliIdentity,
const std::string &vid, const std::string &encryptionKey) {
try {
const time_t now = time(nullptr);
const char *const sql =
"UPDATE TAPE SET "
"ENCRYPTION_KEY = :ENCRYPTION_KEY,"
"LAST_UPDATE_USER_NAME = :LAST_UPDATE_USER_NAME,"
"LAST_UPDATE_HOST_NAME = :LAST_UPDATE_HOST_NAME,"
"LAST_UPDATE_TIME = :LAST_UPDATE_TIME "
"WHERE "
"VID = :VID";
auto conn = m_connPool.getConn();
auto stmt = conn->createStmt(sql, rdbms::Stmt::AutocommitMode::ON);
stmt->bindString(":ENCRYPTION_KEY", encryptionKey);
stmt->bindString(":LAST_UPDATE_USER_NAME", cliIdentity.username);
stmt->bindString(":LAST_UPDATE_HOST_NAME", cliIdentity.host);
stmt->bindUint64(":LAST_UPDATE_TIME", now);
stmt->bindString(":VID", vid);
stmt->executeNonQuery();
if(0 == stmt->getNbAffectedRows()) {
throw exception::UserError(std::string("Cannot modify tape ") + vid + " because it does not exist");
}
} catch(exception::UserError &) {
throw;
} catch (exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
//------------------------------------------------------------------------------
......@@ -1959,7 +1986,7 @@ void RdbmsCatalogue::modifyRequesterGroupMountPolicy(const common::dataStructure
}
//------------------------------------------------------------------------------
// modifyRequesterComment
// modifyRequesterGroupComment
//------------------------------------------------------------------------------
void RdbmsCatalogue::modifyRequesterGroupComment(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &instanceName, const std::string &requesterGroupName, const std::string &comment) {
throw exception::Exception(std::string(__FUNCTION__) + " not implemented");
......
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