Coverage Report

Created: 2025-04-19 16:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/build/source/nativelink-service/src/push_server.rs
Line
Count
Source
1
// Copyright 2025 The NativeLink Authors. All rights reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//    http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
use std::convert::Into;
16
17
use nativelink_config::cas_server::PushConfig;
18
use nativelink_error::{Error, ResultExt};
19
use nativelink_proto::build::bazel::remote::asset::v1::push_server::{Push, PushServer as Server};
20
use nativelink_proto::build::bazel::remote::asset::v1::{
21
    PushBlobRequest, PushBlobResponse, PushDirectoryRequest, PushDirectoryResponse,
22
};
23
use nativelink_store::store_manager::StoreManager;
24
use nativelink_util::digest_hasher::make_ctx_for_hash_func;
25
use nativelink_util::origin_event::OriginEventContext;
26
use tonic::{Request, Response, Status};
27
use tracing::{Level, error_span, instrument};
28
29
#[derive(Debug, Clone, Copy)]
30
pub struct PushServer {}
31
32
impl PushServer {
33
1
    pub const fn new(_config: &PushConfig, _store_manager: &StoreManager) -> Result<Self, Error> {
34
1
        Ok(PushServer {})
35
1
    }
36
37
0
    pub fn into_service(self) -> Server<PushServer> {
38
0
        Server::new(self)
39
0
    }
40
41
1
    async fn inner_push_blob(
42
1
        &self,
43
1
        _request: PushBlobRequest,
44
1
    ) -> Result<Response<PushBlobResponse>, Error> {
45
1
        Ok(Response::new(PushBlobResponse {}))
46
1
    }
47
}
48
49
#[tonic::async_trait]
50
impl Push for PushServer {
51
    #[allow(clippy::blocks_in_conditions)]
52
    #[instrument(
53
        err,
54
        ret(level = Level::INFO),
55
        level = Level::ERROR,
56
        skip_all,
57
        fields(request = ?grpc_request.get_ref())
58
    )]
59
    async fn push_blob(
60
        &self,
61
        grpc_request: Request<PushBlobRequest>,
62
2
    ) -> Result<Response<PushBlobResponse>, Status> {
63
1
        let request = grpc_request.into_inner();
64
1
        let ctx = OriginEventContext::new(|| 
&request0
).await;
65
1
        let resp: Result<Response<PushBlobResponse>, Status> =
66
1
            make_ctx_for_hash_func(request.digest_function)
67
1
                .err_tip(|| 
"In PushServer::push_blob"0
)
?0
68
1
                .wrap_async(error_span!("push_push_blob"), self.inner_push_blob(request))
69
1
                .await
70
1
                .err_tip(|| 
"Failed on push_blob() command"0
)
71
1
                .map_err(Into::into);
72
1
        ctx.emit(|| 
&resp0
).await;
73
1
        resp
74
2
    }
75
76
    #[allow(clippy::blocks_in_conditions)]
77
    #[instrument(
78
        err,
79
        ret(level = Level::INFO),
80
        level = Level::ERROR,
81
        skip_all,
82
        fields(request = ?_grpc_request.get_ref())
83
    )]
84
    async fn push_directory(
85
        &self,
86
        _grpc_request: Request<PushDirectoryRequest>,
87
0
    ) -> Result<Response<PushDirectoryResponse>, Status> {
88
0
        todo!()
89
0
    }
90
}