Add users from configfile

This commit is contained in:
2025-06-07 14:33:00 +02:00
parent 2d1eed4289
commit 3db83f14fe
3 changed files with 29 additions and 6 deletions

View File

@@ -1 +1,2 @@
NEXTCLOUD_CONTAINER_NAME=nextcloud
NEXTCLOUD_USERS=username1 username2 username3

View File

@@ -106,6 +106,8 @@ void scannerThreadFunc()
int main()
{
manager.tryAddUsersFromConfig(cfm);
std::thread readingThread(readingThreadFunc);
std::thread scannerThread(scannerThreadFunc);

View File

@@ -7,6 +7,7 @@
#include <set>
#include <sstream>
#include <mutex>
#include <stdexcept>
#include "definitions.h"
#include "configfilemanager.h"
@@ -25,28 +26,30 @@ public:
addUser(splitString(line, '|').at(USER_LOG_LOCATION));
}
void addUser(std::string &user)
void addUser(const std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 0)
{
users[user] = false;
std::cout << "User added the list: " << user << std::endl;
}
}
void removeUser(std::string &user)
void removeUser(const std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
users.erase(user);
std::cout << "User removed the list: " << user << std::endl;
}
bool isContains(std::string &user)
bool isContains(const std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
return users.count(user) == 1;
}
void setUserFlagged(std::string &user)
void setUserFlagged(const std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 1)
@@ -55,7 +58,7 @@ public:
}
}
void setUserUnflagged(std::string &user)
void setUserUnflagged(const std::string &user)
{
std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 1)
@@ -116,6 +119,23 @@ public:
return false;
}
void tryAddUsersFromConfig(configfilemanager &cfm)
{
try
{
std::vector<std::string> alluser = splitString(cfm.at("NEXTCLOUD_USERS"), ' ');
for (const std::string& user : alluser)
{
addUser(user);
}
}
catch (std::exception e)
{
std::cerr << "No user added from configuration file" << std::endl;
}
}
};
#endif // _USERMAN_H