2 Commits

Author SHA1 Message Date
65fc484fa4 fix
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
2024-09-14 19:31:21 -05:00
253978bc5f update 2024-09-14 19:12:42 -05:00
2 changed files with 18 additions and 11 deletions

View File

@ -39,30 +39,37 @@ auto server::check_authorization(const httplib::Request &req) -> bool {
return false;
}
const auto authorization = req.get_header_value("Authorization");
auto authorization = req.get_header_value("Authorization");
if (authorization.empty()) {
utils::error::raise_error(function_name, "Authorization header is not set");
return false;
}
const auto auth_parts = utils::string::split(authorization, ' ', true);
auto auth_parts = utils::string::split(authorization, ' ', true);
if (auth_parts.empty()) {
utils::error::raise_error(function_name, "Authorization header is empty");
return false;
}
const auto auth_type = auth_parts[0U];
auto auth_type = auth_parts[0U];
if (auth_type != "Basic") {
utils::error::raise_error(function_name, "Authorization is not Basic");
return false;
}
const auto data = macaron::Base64::Decode(authorization.substr(6U));
const auto auth =
utils::string::split(std::string(data.begin(), data.end()), ':', true);
if (auth.size() != 2U) {
auto data = macaron::Base64::Decode(authorization.substr(6U));
auto auth_str = std::string(data.begin(), data.end());
auto auth = utils::string::split(auth_str, ':', true);
if (auth.size() < 2U) {
utils::error::raise_error(function_name, "Authorization is not valid");
return false;
}
const auto &user = auth[0U];
const auto &pwd = auth[1U];
auto user = auth.at(0U);
auth.erase(auth.begin());
auto pwd = utils::string::join(auth, ':');
return (user == config_.get_api_user()) && (pwd == config_.get_api_auth());
}

View File

@ -34,8 +34,8 @@ namespace repertory::cli::actions {
const std::string &data_directory,
const provider_type &prov,
const std::string &unique_id,
std::string user, std::string password)
-> exit_code {
std::string user,
std::string password) -> exit_code {
lock_data lock(prov, unique_id);
const auto res = lock.grab_lock(1U);
if (res == lock_result::success) {