diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-01 14:56:32 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-07-04 16:05:08 +0200 |
commit | 9ab21a7f3d7e349b05ceaad5862d7e72a6d7e7b4 (patch) | |
tree | 269b95c86875d9bd4fe16e117aa9ba75b6c60304 /src/other_tools/just_mr/setup_utils.cpp | |
parent | 0cbc8e226b39ec731373b80024e23cc0580c27ac (diff) | |
download | justbuild-9ab21a7f3d7e349b05ceaad5862d7e72a6d7e7b4.tar.gz |
Pass Auth::TLS instance to BazelApi and ServeApi
Diffstat (limited to 'src/other_tools/just_mr/setup_utils.cpp')
-rw-r--r-- | src/other_tools/just_mr/setup_utils.cpp | 94 |
1 files changed, 43 insertions, 51 deletions
diff --git a/src/other_tools/just_mr/setup_utils.cpp b/src/other_tools/just_mr/setup_utils.cpp index 86e0615c..7ed61897 100644 --- a/src/other_tools/just_mr/setup_utils.cpp +++ b/src/other_tools/just_mr/setup_utils.cpp @@ -26,48 +26,6 @@ #include "src/buildtool/logging/logger.hpp" #include "src/other_tools/just_mr/exit_codes.hpp" -namespace { - -void SetupAuthConfig(MultiRepoRemoteAuthArguments const& authargs) noexcept { - bool use_tls{false}; - if (authargs.tls_ca_cert) { - use_tls = true; - if (not Auth::TLS::Instance().SetCACertificate(*authargs.tls_ca_cert)) { - Logger::Log(LogLevel::Error, - "Could not read '{}' certificate.", - authargs.tls_ca_cert->string()); - std::exit(kExitConfigError); - } - } - if (authargs.tls_client_cert) { - use_tls = true; - if (not Auth::TLS::Instance().SetClientCertificate( - *authargs.tls_client_cert)) { - Logger::Log(LogLevel::Error, - "Could not read '{}' certificate.", - authargs.tls_client_cert->string()); - std::exit(kExitConfigError); - } - } - if (authargs.tls_client_key) { - use_tls = true; - if (not Auth::TLS::Instance().SetClientKey(*authargs.tls_client_key)) { - Logger::Log(LogLevel::Error, - "Could not read '{}' key.", - authargs.tls_client_key->string()); - std::exit(kExitConfigError); - } - } - - if (use_tls) { - if (not Auth::TLS::Instance().Validate()) { - std::exit(kExitConfigError); - } - } -} - -} // namespace - namespace JustMR::Utils { void ReachableRepositories( @@ -235,9 +193,47 @@ auto ReadConfiguration( } } -void SetupRemoteConfig(std::optional<std::string> const& remote_exec_addr, - std::optional<std::string> const& remote_serve_addr, - MultiRepoRemoteAuthArguments const& auth) noexcept { +void SetupAuthConfig(MultiRepoRemoteAuthArguments const& authargs) noexcept { + bool use_tls{false}; + if (authargs.tls_ca_cert) { + use_tls = true; + if (not Auth::TLS::Instance().SetCACertificate(*authargs.tls_ca_cert)) { + Logger::Log(LogLevel::Error, + "Could not read '{}' certificate.", + authargs.tls_ca_cert->string()); + std::exit(kExitConfigError); + } + } + if (authargs.tls_client_cert) { + use_tls = true; + if (not Auth::TLS::Instance().SetClientCertificate( + *authargs.tls_client_cert)) { + Logger::Log(LogLevel::Error, + "Could not read '{}' certificate.", + authargs.tls_client_cert->string()); + std::exit(kExitConfigError); + } + } + if (authargs.tls_client_key) { + use_tls = true; + if (not Auth::TLS::Instance().SetClientKey(*authargs.tls_client_key)) { + Logger::Log(LogLevel::Error, + "Could not read '{}' key.", + authargs.tls_client_key->string()); + std::exit(kExitConfigError); + } + } + + if (use_tls) { + if (not Auth::TLS::Instance().Validate()) { + std::exit(kExitConfigError); + } + } +} + +void SetupRemoteConfig( + std::optional<std::string> const& remote_exec_addr, + std::optional<std::string> const& remote_serve_addr) noexcept { // if only a serve endpoint address is given, we assume it is one that acts // also as remote-execution auto remote_addr = remote_exec_addr ? remote_exec_addr : remote_serve_addr; @@ -245,8 +241,6 @@ void SetupRemoteConfig(std::optional<std::string> const& remote_exec_addr, return; } - // setup authentication - SetupAuthConfig(auth); // setup remote if (not RemoteExecutionConfig::SetRemoteAddress(*remote_addr)) { Logger::Log(LogLevel::Error, @@ -256,15 +250,13 @@ void SetupRemoteConfig(std::optional<std::string> const& remote_exec_addr, } } -auto CreateServeConfig(std::optional<std::string> const& remote_serve_addr, - MultiRepoRemoteAuthArguments const& auth) noexcept +auto CreateServeConfig( + std::optional<std::string> const& remote_serve_addr) noexcept -> std::optional<RemoteServeConfig> { RemoteServeConfig::Builder builder; auto config = builder.SetRemoteAddress(remote_serve_addr).Build(); if (config) { - // setup authentication - SetupAuthConfig(auth); return *std::move(config); } |