Skip to content

Commit

Permalink
local_cas supports GetCapabilities request (pantsbuild#10226)
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed Jul 1, 2020
1 parent 238b3b7 commit 77a111c
Showing 1 changed file with 52 additions and 12 deletions.
64 changes: 52 additions & 12 deletions src/rust/engine/testutil/mock/src/cas.rs
Expand Up @@ -149,8 +149,11 @@ impl StubCAS {
responder.clone(),
))
.register_service(
bazel_protos::remote_execution_grpc::create_content_addressable_storage(responder),
bazel_protos::remote_execution_grpc::create_content_addressable_storage(responder.clone()),
)
.register_service(bazel_protos::remote_execution_grpc::create_capabilities(
responder,
))
.bind("localhost", port)
.build()
.unwrap();
Expand Down Expand Up @@ -226,6 +229,22 @@ macro_rules! check_auth {
};
}

macro_rules! check_instance_name {
($self:ident, $req:ident, $sink:ident) => {
if $req.instance_name != $self.instance_name() {
$sink.fail(grpcio::RpcStatus::new(
grpcio::RpcStatusCode::NOT_FOUND,
Some(format!(
"Wrong instance_name; want {:?} got {:?}",
$self.instance_name(),
$req.instance_name
)),
));
return;
}
};
}

impl StubCASResponder {
fn instance_name(&self) -> String {
self.instance_name.clone().unwrap_or_default()
Expand Down Expand Up @@ -488,17 +507,9 @@ impl bazel_protos::remote_execution_grpc::ContentAddressableStorage for StubCASR
));
return;
}
if req.instance_name != self.instance_name() {
sink.fail(grpcio::RpcStatus::new(
grpcio::RpcStatusCode::NOT_FOUND,
Some(format!(
"Wrong instance_name; want {:?} got {:?}",
self.instance_name(),
req.instance_name
)),
));
return;
}

check_instance_name!(self, req, sink);

let blobs = self.blobs.lock();
let mut response = bazel_protos::remote_execution::FindMissingBlobsResponse::new();
for digest in req.get_blob_digests() {
Expand Down Expand Up @@ -546,3 +557,32 @@ impl bazel_protos::remote_execution_grpc::ContentAddressableStorage for StubCASR
unimplemented!()
}
}

impl bazel_protos::remote_execution_grpc::Capabilities for StubCASResponder {
fn get_capabilities(
&self,
_ctx: grpcio::RpcContext<'_>,
req: bazel_protos::remote_execution::GetCapabilitiesRequest,
sink: grpcio::UnarySink<bazel_protos::remote_execution::ServerCapabilities>,
) {
check_instance_name!(self, req, sink);

let mut response = bazel_protos::remote_execution::ServerCapabilities::new();
let cache_capabilities = response.mut_cache_capabilities();
cache_capabilities.set_digest_function(vec![
bazel_protos::remote_execution::DigestFunction_Value::SHA256,
]);
cache_capabilities.max_batch_total_size_bytes = 0;

response.mut_execution_capabilities().digest_function =
bazel_protos::remote_execution::DigestFunction_Value::SHA256;
response.mut_execution_capabilities().exec_enabled = true;

let mut max_semver = bazel_protos::semver::SemVer::new();
max_semver.major = 2;
max_semver.minor = 999;
response.set_high_api_version(max_semver);

sink.success(response);
}
}

0 comments on commit 77a111c

Please sign in to comment.