diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-02 11:06:23 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-09 13:07:13 +0200 |
commit | d49ec46214178d429215312499806f9feef2ab7d (patch) | |
tree | 8a3679f54868ce94602ccded27d8fd05a849f7de /src/buildtool/execution_api/execution_service | |
parent | 7eafe5779703275d455558120efc754c2dcc3c01 (diff) | |
download | justbuild-d49ec46214178d429215312499806f9feef2ab7d.tar.gz |
Validate hashes in ActionCacheServiceImpl
Diffstat (limited to 'src/buildtool/execution_api/execution_service')
-rw-r--r-- | src/buildtool/execution_api/execution_service/TARGETS | 2 | ||||
-rw-r--r-- | src/buildtool/execution_api/execution_service/ac_server.cpp | 33 |
2 files changed, 18 insertions, 17 deletions
diff --git a/src/buildtool/execution_api/execution_service/TARGETS b/src/buildtool/execution_api/execution_service/TARGETS index f52efc26..78e0fe33 100644 --- a/src/buildtool/execution_api/execution_service/TARGETS +++ b/src/buildtool/execution_api/execution_service/TARGETS @@ -45,8 +45,8 @@ ] , "private-deps": [ ["src/buildtool/logging", "log_level"] - , ["src/utils/cpp", "verify_hash"] , ["src/buildtool/common", "common"] + , ["src/buildtool/common", "artifact_digest_factory"] ] } , "cas_server": diff --git a/src/buildtool/execution_api/execution_service/ac_server.cpp b/src/buildtool/execution_api/execution_service/ac_server.cpp index cc59a983..3da0bf1f 100644 --- a/src/buildtool/execution_api/execution_service/ac_server.cpp +++ b/src/buildtool/execution_api/execution_service/ac_server.cpp @@ -16,35 +16,36 @@ #include "fmt/core.h" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/storage/garbage_collector.hpp" -#include "src/utils/cpp/verify_hash.hpp" auto ActionCacheServiceImpl::GetActionResult( ::grpc::ServerContext* /*context*/, const ::bazel_re::GetActionResultRequest* request, ::bazel_re::ActionResult* response) -> ::grpc::Status { - if (auto error_msg = IsAHash(request->action_digest().hash()); error_msg) { - logger_.Emit(LogLevel::Debug, "{}", *error_msg); - return ::grpc::Status{::grpc::StatusCode::INVALID_ARGUMENT, *error_msg}; + auto action_digest = ArtifactDigestFactory::FromBazel( + storage_config_.hash_function.GetType(), request->action_digest()); + if (not action_digest) { + logger_.Emit(LogLevel::Debug, "{}", action_digest.error()); + return ::grpc::Status{::grpc::StatusCode::INVALID_ARGUMENT, + std::move(action_digest).error()}; } - logger_.Emit(LogLevel::Trace, - "GetActionResult: {}", - request->action_digest().hash()); - auto lock = GarbageCollector::SharedLock(storage_config_); + logger_.Emit(LogLevel::Trace, "GetActionResult: {}", action_digest->hash()); + auto const lock = GarbageCollector::SharedLock(storage_config_); if (not lock) { - auto str = fmt::format("Could not acquire SharedLock"); + static constexpr auto str = "Could not acquire SharedLock"; logger_.Emit(LogLevel::Error, str); return grpc::Status{grpc::StatusCode::INTERNAL, str}; } - ArtifactDigest const a_digest{request->action_digest()}; - auto x = storage_.ActionCache().CachedResult(a_digest); - if (not x) { - return grpc::Status{grpc::StatusCode::NOT_FOUND, - fmt::format("{} missing from AC", a_digest.hash())}; + auto action_result = storage_.ActionCache().CachedResult(*action_digest); + if (not action_result) { + return grpc::Status{ + grpc::StatusCode::NOT_FOUND, + fmt::format("{} missing from AC", action_digest->hash())}; } - *response = *x; + *response = *std::move(action_result); return ::grpc::Status::OK; } @@ -53,7 +54,7 @@ auto ActionCacheServiceImpl::UpdateActionResult( const ::bazel_re::UpdateActionResultRequest* /*request*/, ::bazel_re::ActionResult* /*response*/) -> ::grpc::Status { - auto const* str = "UpdateActionResult not implemented"; + static auto constexpr str = "UpdateActionResult not implemented"; logger_.Emit(LogLevel::Error, str); return ::grpc::Status{grpc::StatusCode::UNIMPLEMENTED, str}; } |