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_CONTAINER_NAME=nextcloud
NEXTCLOUD_USERS=username1 username2 username3

View File

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

View File

@@ -7,6 +7,7 @@
#include <set> #include <set>
#include <sstream> #include <sstream>
#include <mutex> #include <mutex>
#include <stdexcept>
#include "definitions.h" #include "definitions.h"
#include "configfilemanager.h" #include "configfilemanager.h"
@@ -25,28 +26,30 @@ public:
addUser(splitString(line, '|').at(USER_LOG_LOCATION)); 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); std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 0) if (users.count(user) == 0)
{ {
users[user] = false; 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); std::lock_guard<std::mutex> lock(mtx);
users.erase(user); 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); std::lock_guard<std::mutex> lock(mtx);
return users.count(user) == 1; return users.count(user) == 1;
} }
void setUserFlagged(std::string &user) void setUserFlagged(const std::string &user)
{ {
std::lock_guard<std::mutex> lock(mtx); std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 1) 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); std::lock_guard<std::mutex> lock(mtx);
if (users.count(user) == 1) if (users.count(user) == 1)
@@ -116,6 +119,23 @@ public:
return false; 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 #endif // _USERMAN_H