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

View File

@ -31,7 +31,7 @@
* Added Sia API version check prior to mounting
* Added back `-cv` (check version) CLI option
* Continue documentation updates
* Fixed setting `ApiAuth` via `set_value_by_name`
* Fixed setting `ApiPassword` via `set_value_by_name`
* Fixed setting `HostConfig.ApiUser` via `set_value_by_name`
* Fixed setting `HostConfig.Path` via `set_value_by_name`
* Fixed setting `HostConfig.Protocol` via `set_value_by_name`

View File

@ -132,7 +132,7 @@ Only 64-bit operating systems are supported
```json
{
"ApiAuth": "<random generated rpc password>",
"ApiPassword": "<random generated rpc password>",
"ApiPort": 10000,
"ApiUser": "repertory",
"DatabaseType": "rocksdb",
@ -220,7 +220,7 @@ Only 64-bit operating systems are supported
```json
{
"ApiAuth": "<random generated rpc password>",
"ApiPassword": "<random generated rpc password>",
"ApiPort": 10100,
"ApiUser": "repertory",
"DatabaseType": "rocksdb",
@ -360,7 +360,7 @@ for S3 providers.
```json
{
"ApiAuth": "<random generated rpc password>",
"ApiPassword": "<random generated rpc password>",
"ApiPort": 10010,
"ApiUser": "repertory",
"EnableDriveEvents": false,

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>();

View File

@ -30,7 +30,7 @@ public:
mgmt_app_config();
private:
atomic<std::string> api_auth_{"repertory"};
atomic<std::string> api_password_{"repertory"};
std::atomic<std::uint16_t> api_port_{default_ui_mgmt_port};
atomic<std::string> api_user_{"repertory"};
std::unordered_map<provider_type,
@ -42,7 +42,9 @@ private:
void save() const;
public:
[[nodiscard]] auto get_api_auth() const -> std::string { return api_auth_; }
[[nodiscard]] auto get_api_password() const -> std::string {
return api_password_;
}
[[nodiscard]] auto get_api_port() const -> std::uint16_t { return api_port_; }

View File

@ -90,7 +90,7 @@ mgmt_app_config::mgmt_app_config() {
nlohmann::json data;
if (utils::file::read_json_file(config_file, data)) {
api_auth_ = data.at(JSON_API_PASSWORD).get<std::string>();
api_password_ = data.at(JSON_API_PASSWORD).get<std::string>();
api_port_ = data.at(JSON_API_PORT).get<std::uint16_t>();
api_user_ = data.at(JSON_API_USER).get<std::string>();
locations_ = from_json(data.at(JSON_MOUNT_LOCATIONS));
@ -135,7 +135,7 @@ void mgmt_app_config::save() const {
}
nlohmann::json data;
data[JSON_API_PASSWORD] = api_auth_;
data[JSON_API_PASSWORD] = api_password_;
data[JSON_API_PORT] = api_port_;
data[JSON_API_USER] = api_user_;
data[JSON_MOUNT_LOCATIONS] = to_json(locations_);

View File

@ -185,9 +185,9 @@ static void defaults_tests(const json &json_data, provider_type prov) {
}
fmt::println("testing default|{}-{}", app_config::get_provider_name(prov),
JSON_API_AUTH);
ASSERT_EQ(std::size_t(default_api_auth_size),
json_data.at(JSON_API_AUTH).get<std::string>().size());
JSON_API_PASSWORD);
ASSERT_EQ(std::size_t(default_api_password_size),
json_data.at(JSON_API_PASSWORD).get<std::string>().size());
for (const auto &[key, value] : json_defaults.items()) {
fmt::println("testing default|{}-{}", app_config::get_provider_name(prov),
key);
@ -216,11 +216,11 @@ static void common_tests(app_config &config, provider_type prov) {
ASSERT_EQ(config.get_provider_type(), prov);
std::map<std::string_view, std::function<void(app_config &)>> methods{
{JSON_API_AUTH,
{JSON_API_PASSWORD,
[](app_config &cfg) {
test_getter_setter(cfg, &app_config::get_api_auth,
&app_config::set_api_auth, "", "auth",
JSON_API_AUTH, "auth2");
JSON_API_PASSWORD, "auth2");
}},
{JSON_API_PORT,
[](app_config &cfg) {

View File

@ -124,7 +124,7 @@ String getBaseUri() {
List<Validator> getSettingValidators(String settingPath) {
switch (settingPath) {
case 'ApiAuth':
case 'ApiPassword':
return [notEmptyValidator];
case 'DatabaseType':
return [(value) => constants.databaseTypeList.contains(value)];

View File

@ -346,7 +346,7 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
widget.settings.forEach((key, value) {
switch (key) {
case 'ApiAuth':
case 'ApiPassword':
{
_addPasswordSetting(
commonSettings,