Skip to content

Commit

Permalink
ISSUE #697 decomissioned Role, User and Camera types
Browse files Browse the repository at this point in the history
  • Loading branch information
sebjf committed Sep 18, 2024
1 parent 7912014 commit 7c83af2
Show file tree
Hide file tree
Showing 52 changed files with 210 additions and 5,382 deletions.
61 changes: 0 additions & 61 deletions bouncer/src/repo/core/handler/repo_database_handler_abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include <string>

#include "../model/bson/repo_bson.h"
#include "../model/bson/repo_bson_role.h"
#include "../model/bson/repo_bson_user.h"

namespace repo {
namespace core {
Expand Down Expand Up @@ -206,16 +204,6 @@ namespace repo {
const std::string &contentType = "binary/octet-stream"
) = 0;

/**
* Insert a role into the database
* @param role role bson to insert
* @param errmsg error message
* @return returns true upon success
*/
virtual bool insertRole(
const repo::core::model::RepoRole &role,
std::string &errmsg) = 0;

/**
* Update/insert a single document in database.collection
* If the document exists, update it, if it doesn't, insert it
Expand All @@ -233,16 +221,6 @@ namespace repo {
const bool &overwrite,
std::string &errMsg) = 0;

/**
* Insert a user into the database
* @param user user bson to insert
* @param errmsg error message
* @return returns true upon success
*/
virtual bool insertUser(
const repo::core::model::RepoUser &user,
std::string &errmsg) = 0;

/**
* Remove a collection from the database
* @param database the database the collection resides in
Expand Down Expand Up @@ -302,45 +280,6 @@ namespace repo {
const std::string &fileName,
std::string &errMsg) = 0;

/**
* Remove a role from the database
* @param role user bson to remove
* @param errmsg error message
* @return returns true upon success
*/
virtual bool dropRole(
const repo::core::model::RepoRole &role,
std::string &errmsg) = 0;

/**
* Remove a user from the database
* @param user user bson to remove
* @param errmsg error message
* @return returns true upon success
*/
virtual bool dropUser(
const repo::core::model::RepoUser &user,
std::string &errmsg) = 0;

/**
* Update a role in the database
* @param role role bson to update
* @param errmsg error message
* @return returns true upon success
*/
virtual bool updateRole(
const repo::core::model::RepoRole &role,
std::string &errmsg) = 0;

/**
* Update a user in the database
* @param user user bson to update
* @param errmsg error message
* @return returns true upon success
*/
virtual bool updateUser(
const repo::core::model::RepoUser &user,
std::string &errmsg) = 0;
/*
* ------------- Query operations --------------
*/
Expand Down
128 changes: 0 additions & 128 deletions bouncer/src/repo/core/handler/repo_database_handler_mongo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,134 +1061,6 @@ bool MongoDatabaseHandler::insertRawFile(
return success;
}

bool MongoDatabaseHandler::performRoleCmd(
const OPERATION &op,
const repo::core::model::RepoRole &role,
std::string &errMsg)
{
bool success = false;

if (!role.isEmpty())
{
if (role.getName().empty() || role.getDatabase().empty())
{
errMsg += "Role bson does not contain role name/database name";
}
else {
try {
mongo::BSONObjBuilder cmdBuilder;
std::string roleName = role.getName();
switch (op)
{
case OPERATION::INSERT:
cmdBuilder << "createRole" << roleName;
break;
case OPERATION::UPDATE:
cmdBuilder << "updateRole" << roleName;
break;
case OPERATION::DROP:
cmdBuilder << "dropRole" << roleName;
}

if (op != OPERATION::DROP)
{
repo::core::model::RepoBSON privileges = role.getObjectField(REPO_ROLE_LABEL_PRIVILEGES);
cmdBuilder.appendArray("privileges", privileges);

repo::core::model::RepoBSON inheritedRoles = role.getObjectField(REPO_ROLE_LABEL_INHERITED_ROLES);

cmdBuilder.appendArray("roles", inheritedRoles);
}

mongo::BSONObj info;
auto cmd = cmdBuilder.obj();
success = worker->runCommand(role.getDatabase(), cmd, info);

std::string cmdError = info.getStringField("errmsg");
if (!cmdError.empty())
{
success = false;
errMsg += cmdError;
}
}
catch (mongo::DBException &e)
{
success = false;
std::string errString(e.what());
errMsg += errString;
}
}
}
else
{
errMsg += "Role bson is empty";
}

return success;
}

bool MongoDatabaseHandler::performUserCmd(
const OPERATION &op,
const repo::core::model::RepoUser &user,
std::string &errMsg)
{
bool success = false;

if (!user.isEmpty())
{
try {
repo::core::model::RepoBSONBuilder cmdBuilder;
std::string username = user.getUserName();
switch (op)
{
case OPERATION::INSERT:
cmdBuilder.append("createUser", username);
break;
case OPERATION::UPDATE:
cmdBuilder.append("updateUser", username);
break;
case OPERATION::DROP:
cmdBuilder.append("dropUser", username);
}

if (op != OPERATION::DROP)
{
std::string pw = user.getCleartextPassword();
if (!pw.empty())
cmdBuilder.append("pwd", pw);

repo::core::model::RepoBSON customData = user.getCustomDataBSON();
if (!customData.isEmpty())
cmdBuilder.append("customData", customData);

//compulsory, so no point checking if it's empty
cmdBuilder.appendArray("roles", user.getRolesBSON());
}

mongo::BSONObj info;
success = worker->runCommand(ADMIN_DATABASE, cmdBuilder.mongoObj(), info);

std::string cmdError = info.getStringField("errmsg");
if (!cmdError.empty())
{
success = false;
errMsg += cmdError;
}
}
catch (mongo::DBException &e)
{
std::string errString(e.what());
errMsg += errString;
}
}
else
{
errMsg += "User bson is empty";
}

return success;
}

bool MongoDatabaseHandler::upsertDocument(
const std::string &database,
const std::string &collection,
Expand Down
111 changes: 0 additions & 111 deletions bouncer/src/repo/core/handler/repo_database_handler_mongo.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
#include "connectionpool/repo_connection_pool_mongo.h"
#include "../model/bson/repo_bson.h"
#include "../model/bson/repo_bson_builder.h"
#include "../model/bson/repo_bson_role.h"
#include "../model/bson/repo_bson_user.h"
#include "../../lib/repo_stack.h"

namespace repo {
Expand Down Expand Up @@ -343,32 +341,6 @@ namespace repo {
const std::string &fileName,
std::string &errMsg);

/**
* Remove a role from the database
* @param role user bson to remove
* @param errmsg error message
* @return returns true upon success
*/
bool dropRole(
const repo::core::model::RepoRole &role,
std::string &errmsg)
{
return performRoleCmd(OPERATION::DROP, role, errmsg);
}

/**
* Remove a user from the database
* @param user user bson to remove
* @param errmsg error message
* @return returns true upon success
*/
bool dropUser(
const repo::core::model::RepoUser &user,
std::string &errmsg)
{
return performUserCmd(OPERATION::DROP, user, errmsg);
}

/**
* Insert a single document in database.collection
* @param database name
Expand Down Expand Up @@ -417,32 +389,6 @@ namespace repo {
const std::string &contentType = "binary/octet-stream"
);

/**
* Insert a role into the database
* @param role role bson to insert
* @param errmsg error message
* @return returns true upon success
*/
bool insertRole(
const repo::core::model::RepoRole &role,
std::string &errmsg)
{
return performRoleCmd(OPERATION::INSERT, role, errmsg);
}

/**
* Insert a user into the database
* @param user user bson to insert
* @param errmsg error message
* @return returns true upon success
*/
bool insertUser(
const repo::core::model::RepoUser &user,
std::string &errmsg)
{
return performUserCmd(OPERATION::INSERT, user, errmsg);
}

/**
* Update/insert a single document in database.collection
* If the document exists, update it, if it doesn't, insert it
Expand All @@ -460,32 +406,6 @@ namespace repo {
const bool &overwrite,
std::string &errMsg);

/**
* Update a role in the database
* @param role role bson to update
* @param errmsg error message
* @return returns true upon success
*/
bool updateRole(
const repo::core::model::RepoRole &role,
std::string &errmsg)
{
return performRoleCmd(OPERATION::UPDATE, role, errmsg);
}

/**
* Update a user in the database
* @param user user bson to update
* @param errmsg error message
* @return returns true upon success
*/
bool updateUser(
const repo::core::model::RepoUser &user,
std::string &errmsg)
{
return performUserCmd(OPERATION::UPDATE, user, errmsg);
}

/*
* ------------- Query operations --------------
*/
Expand Down Expand Up @@ -666,13 +586,6 @@ namespace repo {
const std::list<std::string>& fields,
bool excludeIdField = false);

/**
* Extract collection name from namespace (db.collection)
* @param namespace as string
* @return returns a string with just the collection name
*/
std::string getCollectionFromNamespace(const std::string &ns);

/**
* Get large file off GridFS
* @param worker the worker to operate with
Expand Down Expand Up @@ -704,30 +617,6 @@ namespace repo {
*/
std::string getProjectFromCollection(const std::string &ns, const std::string &projectExt);

/**
* Perform command on the user
* @param op (insert, drop or update)
* @param role user to modify
* @param errMsg error message if failed
* @return returns true upon success
*/
bool performRoleCmd(
const OPERATION &op,
const repo::core::model::RepoRole &role,
std::string &errMsg);

/**
* Perform command on the user
* @param op (insert, drop or update)
* @param user user to modify
* @param errMsg error message if failed
* @return returns true upon success
*/
bool performUserCmd(
const OPERATION &op,
const repo::core::model::RepoUser &user,
std::string &errMsg);

/**
* Compares two strings.
* @param string 1
Expand Down
Loading

0 comments on commit 7c83af2

Please sign in to comment.