This commit is contained in:
2025-03-15 23:04:18 -05:00
parent 0add5ec944
commit b959af26c4
13 changed files with 44 additions and 34 deletions

View File

@@ -73,7 +73,7 @@ public:
private:
provider_type prov_;
atomic<std::string> api_auth_;
atomic<std::string> api_password_;
std::atomic<std::uint16_t> api_port_;
atomic<std::string> api_user_;
std::atomic<bool> config_changed_;
@@ -123,7 +123,7 @@ private:
auto set_value(dest &dst, const source &src) -> bool;
public:
[[nodiscard]] auto get_api_auth() const -> std::string;
[[nodiscard]] auto get_api_password() const -> std::string;
[[nodiscard]] auto get_api_port() const -> std::uint16_t;
@@ -201,7 +201,7 @@ public:
void save();
void set_api_auth(const std::string &value);
void set_api_password(const std::string &value);
void set_api_port(std::uint16_t value);

View File

@@ -57,7 +57,7 @@ using json = nlohmann::json;
inline constexpr const std::string_view REPERTORY = "repertory";
inline constexpr const std::wstring_view REPERTORY_W = L"repertory";
inline constexpr const std::uint64_t REPERTORY_CONFIG_VERSION = 1ULL;
inline constexpr const std::uint64_t REPERTORY_CONFIG_VERSION = 2ULL;
inline constexpr const std::string_view REPERTORY_DATA_NAME = "repertory2";
inline constexpr const std::string_view REPERTORY_MIN_REMOTE_VERSION = "2.0.0";

View File

@@ -31,7 +31,7 @@ namespace repertory::rpc {
const httplib::Request &req) -> bool {
REPERTORY_USES_FUNCTION_NAME();
if (cfg.get_api_auth().empty() || cfg.get_api_user().empty()) {
if (cfg.get_api_password().empty() || cfg.get_api_user().empty()) {
utils::error::raise_error(function_name,
"authorization user or password is not set");
return false;
@@ -70,7 +70,7 @@ namespace repertory::rpc {
auth.erase(auth.begin());
auto pwd = utils::string::join(auth, ':');
if ((user != cfg.get_api_user()) || (pwd != cfg.get_api_auth())) {
if ((user != cfg.get_api_user()) || (pwd != cfg.get_api_password())) {
utils::error::raise_error(function_name, "authorization failed");
return false;
}

View File

@@ -23,7 +23,7 @@
#define REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_
namespace repertory {
constexpr const auto default_api_auth_size{48U};
constexpr const auto default_api_password_size{48U};
constexpr const auto default_download_timeout_secs{30U};
constexpr const auto default_eviction_delay_mins{1U};
constexpr const auto default_high_freq_interval_secs{std::uint16_t{30U}};
@@ -462,7 +462,6 @@ using meta_provider_callback = std::function<void(directory_item &)>;
inline constexpr const auto JSON_ACCESS_KEY{"AccessKey"};
inline constexpr const auto JSON_AGENT_STRING{"AgentString"};
inline constexpr const auto JSON_API_AUTH{"ApiAuth"};
inline constexpr const auto JSON_API_PARENT{"ApiParent"};
inline constexpr const auto JSON_API_PASSWORD{"ApiPassword"};
inline constexpr const auto JSON_API_PATH{"ApiPath"};

View File

@@ -66,7 +66,7 @@ void app_config::set_stop_requested() { stop_requested.store(true); }
app_config::app_config(const provider_type &prov,
std::string_view data_directory)
: prov_(prov),
api_auth_(utils::generate_random_string(default_api_auth_size)),
api_password_(utils::generate_random_string(default_api_password_size)),
api_port_(default_rpc_port(prov)),
api_user_(std::string{REPERTORY}),
config_changed_(false),
@@ -124,7 +124,7 @@ app_config::app_config(const provider_type &prov,
}
value_get_lookup_ = {
{JSON_API_AUTH, [this]() { return get_api_auth(); }},
{JSON_API_PASSWORD, [this]() { return get_api_password(); }},
{JSON_API_PORT, [this]() { return std::to_string(get_api_port()); }},
{JSON_API_USER, [this]() { return get_api_user(); }},
{JSON_DATABASE_TYPE,
@@ -253,10 +253,10 @@ app_config::app_config(const provider_type &prov,
value_set_lookup_ = {
{
JSON_API_AUTH,
JSON_API_PASSWORD,
[this](const std::string &value) {
set_api_auth(value);
return get_api_auth();
set_api_password(value);
return get_api_password();
},
},
{
@@ -755,7 +755,9 @@ auto app_config::default_rpc_port(const provider_type &prov) -> std::uint16_t {
return PROVIDER_RPC_PORTS.at(static_cast<std::size_t>(prov));
}
auto app_config::get_api_auth() const -> std::string { return api_auth_; }
auto app_config::get_api_password() const -> std::string {
return api_password_;
}
auto app_config::get_api_port() const -> std::uint16_t { return api_port_; }
@@ -816,7 +818,7 @@ auto app_config::get_host_config() const -> host_config { return host_config_; }
auto app_config::get_json() const -> json {
json ret = {
{JSON_API_AUTH, api_auth_},
{JSON_API_PASSWORD, api_password_},
{JSON_API_PORT, api_port_},
{JSON_API_USER, api_user_},
{JSON_DOWNLOAD_TIMEOUT_SECS, download_timeout_secs_},
@@ -1037,7 +1039,7 @@ auto app_config::load() -> bool {
auto found{true};
auto json_document = json::parse(json_text);
get_value(json_document, JSON_API_AUTH, api_auth_, found);
get_value(json_document, JSON_API_PASSWORD, api_password_, found);
get_value(json_document, JSON_API_PORT, api_port_, found);
get_value(json_document, JSON_API_USER, api_user_, found);
get_value(json_document, JSON_DATABASE_TYPE, db_type_, found);
@@ -1094,6 +1096,13 @@ auto app_config::load() -> bool {
set_value(max_cache_size_bytes_, default_max_cache_size_bytes);
}
}
if (version_ == 2U) {
if (json_document.contains("ApiAuth")) {
api_password_ = json_document.at("ApiAuth").get<std::string>();
}
}
found = false;
}
@@ -1132,8 +1141,8 @@ void app_config::save() {
});
}
void app_config::set_api_auth(const std::string &value) {
set_value(api_auth_, value);
void app_config::set_api_password(const std::string &value) {
set_value(api_password_, value);
}
void app_config::set_api_port(std::uint16_t value) {

View File

@@ -45,7 +45,7 @@ void get_api_authentication_data(std::string &user, std::string &password,
if (success) {
if (user.empty() && password.empty()) {
password = data[JSON_API_AUTH].get<std::string>();
password = data[JSON_API_PASSWORD].get<std::string>();
user = data[JSON_API_USER].get<std::string>();
}
port = data[JSON_API_PORT].get<std::uint16_t>();