Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check access and validation of centralized configuration files #514

Open
sdvendramini opened this issue Jan 20, 2025 · 0 comments
Open

Check access and validation of centralized configuration files #514

sdvendramini opened this issue Jan 20, 2025 · 0 comments
Assignees
Labels

Comments

@sdvendramini
Copy link
Member

sdvendramini commented Jan 20, 2025

Description

It is necessary to verify that the file writing and YAML format validation functions are thread-safe to prevent potential race conditions. These functions are used in centralized configuration.

  • Download

    boost::asio::awaitable<bool> Communicator::GetGroupConfigurationFromManager(std::string groupName,
    std::string dstFilePath)
    {
    auto onAuthenticationFailed = [this]()
    {
    TryReAuthenticate();
    };
    bool downloaded = false;
    auto onSuccess = [path = std::move(dstFilePath), &downloaded](const int, const std::string& res)
    {
    std::ofstream file(path, std::ios::binary);
    if (file)
    {
    file << res;
    file.close();
    downloaded = true;
    }
    };
    const auto reqParams = http_client::HttpRequestParams(boost::beast::http::verb::get,
    m_serverUrl,
    "/api/v1/files?file_name=" + groupName +
    config::DEFAULT_SHARED_FILE_EXTENSION,
    m_getHeaderInfo ? m_getHeaderInfo() : "",
    m_verificationMode,
    *m_token);
    co_await m_httpClient->Co_PerformHttpRequest(
    m_token, reqParams, {}, onAuthenticationFailed, m_retryInterval, m_batchSize, onSuccess, {});
    co_return downloaded;
    }

  • Validation

    bool ConfigurationParser::isValidYamlFile(const std::filesystem::path& configFile) const
    {
    try
    {
    YAML::Node mapToValidte = YAML::LoadFile(configFile.string());
    if (!mapToValidte.IsMap() && !mapToValidte.IsSequence())
    {
    throw std::runtime_error("The file does not contain a valid YAML structure.");
    }
    return true;
    }
    catch (const std::exception&)
    {
    return false;
    }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant