std::vector<std::string> keys;
keys.reserve(k_config_key_table.size());
- for (const auto& item : k_config_key_table) {
- keys.emplace_back(item.first);
+ for (const auto& [key, value] : k_config_key_table) {
+ keys.emplace_back(key);
}
std::sort(keys.begin(), keys.end());
for (const auto& key : keys) {
break;
}
- auto result = m_origins.emplace(key, origin);
- if (!result.second) {
- result.first->second = origin;
+ const auto& [element, inserted] = m_origins.emplace(key, origin);
+ if (!inserted) {
+ element->second = origin;
}
}
void
Config::check_key_tables_consistency()
{
- for (const auto& item : k_env_variable_table) {
- if (k_config_key_table.find(item.second) == k_config_key_table.end()) {
+ for (const auto& [key, value] : k_env_variable_table) {
+ if (k_config_key_table.find(value) == k_config_key_table.end()) {
throw core::Error(
"env var {} mapped to {} which is missing from k_config_key_table",
- item.first,
- item.second);
+ key,
+ value);
}
}
}
static void
print_included_files(const Context& ctx, FILE* fp)
{
- for (const auto& item : ctx.included_files) {
- PRINT(fp, "{}\n", item.first);
+ for (const auto& [path, digest] : ctx.included_files) {
+ PRINT(fp, "{}\n", path);
}
}
std::vector<uint32_t> file_info_indexes;
file_info_indexes.reserve(included_files.size());
- for (const auto& item : included_files) {
- file_info_indexes.push_back(get_file_info_index(item.first,
- item.second,
+ for (const auto& [path, digest] : included_files) {
+ file_info_indexes.push_back(get_file_info_index(path,
+ digest,
mf_files,
mf_file_infos,
time_of_compilation,
if (verbosity > 0) {
auto uncacheable_stats = get_stats(FLAG_UNCACHEABLE, verbosity > 1);
std::sort(uncacheable_stats.begin(), uncacheable_stats.end(), cmp_fn);
- for (const auto& descr_count : uncacheable_stats) {
- add_ratio_row(table,
- FMT(" {}:", descr_count.first),
- descr_count.second,
- uncacheable);
+ for (const auto& [name, value] : uncacheable_stats) {
+ add_ratio_row(table, FMT(" {}:", name), value, uncacheable);
}
}
}
if (verbosity > 0) {
auto error_stats = get_stats(FLAG_ERROR, verbosity > 1);
std::sort(error_stats.begin(), error_stats.end(), cmp_fn);
- for (const auto& descr_count : error_stats) {
- add_ratio_row(
- table, FMT(" {}:", descr_count.first), descr_count.second, errors);
+ for (const auto& [name, value] : error_stats) {
+ add_ratio_row(table, FMT(" {}:", name), value, errors);
}
}
}
if (parts[i].empty()) {
continue;
}
- const auto kv_pair = util::split_once(parts[i], '=');
- const auto& key = kv_pair.first;
- const auto& raw_value = kv_pair.second.value_or("true");
+ const auto [key, right_hand_side] = util::split_once(parts[i], '=');
+ const auto& raw_value = right_hand_side.value_or("true");
const auto value =
util::value_or_throw<core::Error>(util::percent_decode(raw_value));
if (key == "read-only") {
m_http_client(get_url(params.url))
{
if (!params.url.user_info().empty()) {
- const auto pair = util::split_once(params.url.user_info(), ':');
- if (!pair.second) {
+ const auto [user, password] = util::split_once(params.url.user_info(), ':');
+ if (!password) {
throw core::Fatal("Expected username:password in URL but got \"{}\"",
params.url.user_info());
}
- m_http_client.set_basic_auth(std::string(pair.first).c_str(),
- std::string(*pair.second).c_str());
+ m_http_client.set_basic_auth(std::string(user).c_str(),
+ std::string(*password).c_str());
}
m_http_client.set_default_headers({
HttpStorage::redact_secrets(Backend::Params& params) const
{
auto& url = params.url;
- const auto user_info = util::split_once(url.user_info(), ':');
- if (user_info.second) {
- url.user_info(FMT("{}:{}", user_info.first, k_redacted_password));
+ const auto [user, password] = util::split_once(url.user_info(), ':');
+ if (password) {
+ url.user_info(FMT("{}:{}", user, k_redacted_password));
}
auto bearer_token_attribute =
std::pair<std::optional<std::string>, std::optional<std::string>>
split_user_info(const std::string& user_info)
{
- const auto pair = util::split_once(user_info, ':');
- if (pair.first.empty()) {
+ const auto [left, right] = util::split_once(user_info, ':');
+ if (left.empty()) {
// redis://HOST
return {std::nullopt, std::nullopt};
- } else if (pair.second) {
+ } else if (right) {
// redis://USERNAME:PASSWORD@HOST
- return {std::string(*pair.second), std::string(pair.first)};
+ return {std::string(left), std::string(*right)};
} else {
// redis://PASSWORD@HOST
- return {std::string(pair.first), std::nullopt};
+ return {std::nullopt, std::string(left)};
}
}
void
RedisStorageBackend::authenticate(const Url& url)
{
- const auto password_username_pair = split_user_info(url.user_info());
- const auto& password = password_username_pair.first;
+ const auto [user, password] = split_user_info(url.user_info());
if (password) {
- const auto& username = password_username_pair.second;
- if (username) {
- LOG("Redis AUTH {} {}", *username, k_redacted_password);
+ if (user) {
+ // redis://user:password@host
+ LOG("Redis AUTH {} {}", *user, k_redacted_password);
util::value_or_throw<Failed>(
- redis_command("AUTH %s %s", username->c_str(), password->c_str()));
+ redis_command("AUTH %s %s", user->c_str(), password->c_str()));
} else {
+ // redis://password@host
LOG("Redis AUTH {}", k_redacted_password);
util::value_or_throw<Failed>(redis_command("AUTH %s", password->c_str()));
}
RedisStorage::redact_secrets(Backend::Params& params) const
{
auto& url = params.url;
- const auto user_info = util::split_once(url.user_info(), ':');
- if (user_info.second) {
- // redis://username:password@host
- url.user_info(FMT("{}:{}", user_info.first, k_redacted_password));
- } else if (!user_info.first.empty()) {
- // redis://password@host
- url.user_info(k_redacted_password);
+ const auto [user, password] = split_user_info(url.user_info());
+ if (password) {
+ if (user) {
+ // redis://user:password@host
+ url.user_info(FMT("{}:{}", *user, k_redacted_password));
+ } else {
+ // redis://password@host
+ url.user_info(k_redacted_password);
+ }
}
}