diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-02-13 15:22:58 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-03-03 16:21:10 +0100 |
commit | 040f9a000aa8dd5f9217d7865fd3652bdb2bdc65 (patch) | |
tree | cf3d0b75a8d3ffc5f11ed2082a374914b270511f /src/other_tools/git_operations/git_config_settings.hpp | |
parent | 07864376504efde66c1e7b1b5185f84a531fe64c (diff) | |
download | justbuild-040f9a000aa8dd5f9217d7865fd3652bdb2bdc65.tar.gz |
Git: Add utility method for honoring SSL certification settings in libgit2 calls
Due to the fact that the libgit2 library handles envariables and
gitconfig entries differently than git, we need to perform these
checks ourselves in order to be fully compliant with git.
This utility method returns the correct callback tat enables or
disables the SSL certificate verification step when interacting
with a remote URL via libgit2 calls.
Diffstat (limited to 'src/other_tools/git_operations/git_config_settings.hpp')
-rw-r--r-- | src/other_tools/git_operations/git_config_settings.hpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/other_tools/git_operations/git_config_settings.hpp b/src/other_tools/git_operations/git_config_settings.hpp new file mode 100644 index 00000000..8aa412e8 --- /dev/null +++ b/src/other_tools/git_operations/git_config_settings.hpp @@ -0,0 +1,49 @@ +// Copyright 2023 Huawei Cloud Computing Technology Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef INCLUDED_SRC_OTHER_TOOLS_GIT_OPERATIONS_GIT_CONFIG_SETTINGS_HPP +#define INCLUDED_SRC_OTHER_TOOLS_GIT_OPERATIONS_GIT_CONFIG_SETTINGS_HPP + +#include <functional> +#include <memory> +#include <optional> +#include <string> + +extern "C" { +struct git_cert; +struct git_config; +using git_transport_certificate_check_cb = auto (*)(git_cert*, + int, + const char*, + void*) -> int; +} + +// Internal type used for logging with AsyncMaps +using anon_logger_t = std::function<void(std::string const&, bool)>; +using anon_logger_ptr = std::shared_ptr<anon_logger_t>; + +namespace GitConfigSettings { + +/// \brief Get a custom SSL certificate check callback to honor the existing +/// Git configuration of a repository trying to connect to a remote. +/// A null config snapshot reference will simply be ignored. +/// Returns nullopt if errors. +[[nodiscard]] auto GetSSLCallback(std::shared_ptr<git_config> const& cfg, + std::string const& url, + anon_logger_ptr const& logger) + -> std::optional<git_transport_certificate_check_cb>; + +} // namespace GitConfigSettings + +#endif // INCLUDED_SRC_OTHER_TOOLS_GIT_OPERATIONS_GIT_CONFIG_SETTINGS_HPP |