Skip to content

Commit

Permalink
StatusService for version endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrit committed Jul 7, 2023
1 parent b3d40c5 commit 43d17a5
Show file tree
Hide file tree
Showing 8 changed files with 460 additions and 44 deletions.
10 changes: 10 additions & 0 deletions proto/steward/v4/steward.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ service ContractCallService {
rpc Simulate(SimulateRequest) returns (SimulateResponse) {}
}

service StatusService {
rpc Version(VersionRequest) returns (VersionResponse) {}
}

/*
* Represents a scheduled function call to a particular Cellar
*/
Expand Down Expand Up @@ -76,3 +80,9 @@ message SimulateResponse {
/// The response body from the Tenderly simulation
string response_body = 2;
}

message VersionRequest {}

message VersionResponse {
string version = 1;
}
5 changes: 3 additions & 2 deletions src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::{
proposals::start_scheduled_cork_proposal_polling_thread, CorkHandler,
},
prelude::*,
proto::contract_call_service_server::ContractCallServiceServer,
server::{self, with_tls, FILE_DESCRIPTOR_SET},
proto::{contract_call_service_server::ContractCallServiceServer, status_service_server::StatusServiceServer},
server::{self, with_tls, FILE_DESCRIPTOR_SET}, status::StatusHandler,
};
use abscissa_core::{clap::Parser, config, Command, FrameworkError, Runnable};
use std::result::Result;
Expand Down Expand Up @@ -57,6 +57,7 @@ impl Runnable for StartCmd {
.expect("tls config was not initialized");
if let Err(err) = with_tls(builder, tls_config)
.add_service(ContractCallServiceServer::new(CorkHandler))
.add_service(StatusServiceServer::new(StatusHandler))
.add_service(proto_descriptor_service)
.serve(server_config.address)
.await
Expand Down
Binary file modified src/gen/proto/descriptor.bin
Binary file not shown.
174 changes: 174 additions & 0 deletions src/gen/proto/steward.v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2983,6 +2983,13 @@ pub struct SimulateResponse {
#[prost(string, tag = "2")]
pub response_body: ::prost::alloc::string::String,
}
#[derive(serde::Deserialize, serde::Serialize, Clone, PartialEq, ::prost::Message)]
pub struct VersionRequest {}
#[derive(serde::Deserialize, serde::Serialize, Clone, PartialEq, ::prost::Message)]
pub struct VersionResponse {
#[prost(string, tag = "1")]
pub version: ::prost::alloc::string::String,
}
#[doc = r" Generated client implementations."]
pub mod contract_call_service_client {
#![allow(unused_variables, dead_code, missing_docs)]
Expand Down Expand Up @@ -3129,6 +3136,67 @@ pub mod simulate_contract_call_service_client {
}
}
}
#[doc = r" Generated client implementations."]
pub mod status_service_client {
#![allow(unused_variables, dead_code, missing_docs)]
use tonic::codegen::*;
pub struct StatusServiceClient<T> {
inner: tonic::client::Grpc<T>,
}
impl StatusServiceClient<tonic::transport::Channel> {
#[doc = r" Attempt to create a new client by connecting to a given endpoint."]
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
where
D: std::convert::TryInto<tonic::transport::Endpoint>,
D::Error: Into<StdError>,
{
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
Ok(Self::new(conn))
}
}
impl<T> StatusServiceClient<T>
where
T: tonic::client::GrpcService<tonic::body::BoxBody>,
T::ResponseBody: Body + HttpBody + Send + 'static,
T::Error: Into<StdError>,
<T::ResponseBody as HttpBody>::Error: Into<StdError> + Send,
{
pub fn new(inner: T) -> Self {
let inner = tonic::client::Grpc::new(inner);
Self { inner }
}
pub fn with_interceptor(inner: T, interceptor: impl Into<tonic::Interceptor>) -> Self {
let inner = tonic::client::Grpc::with_interceptor(inner, interceptor);
Self { inner }
}
pub async fn version(
&mut self,
request: impl tonic::IntoRequest<super::VersionRequest>,
) -> Result<tonic::Response<super::VersionResponse>, tonic::Status> {
self.inner.ready().await.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static("/steward.v4.StatusService/Version");
self.inner.unary(request.into_request(), path, codec).await
}
}
impl<T: Clone> Clone for StatusServiceClient<T> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
}
}
}
impl<T> std::fmt::Debug for StatusServiceClient<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "StatusServiceClient {{ ... }}")
}
}
}
#[doc = r" Generated server implementations."]
pub mod contract_call_service_server {
#![allow(unused_variables, dead_code, missing_docs)]
Expand Down Expand Up @@ -3388,3 +3456,109 @@ pub mod simulate_contract_call_service_server {
const NAME: &'static str = "steward.v4.SimulateContractCallService";
}
}
#[doc = r" Generated server implementations."]
pub mod status_service_server {
#![allow(unused_variables, dead_code, missing_docs)]
use tonic::codegen::*;
#[doc = "Generated trait containing gRPC methods that should be implemented for use with StatusServiceServer."]
#[async_trait]
pub trait StatusService: Send + Sync + 'static {
async fn version(
&self,
request: tonic::Request<super::VersionRequest>,
) -> Result<tonic::Response<super::VersionResponse>, tonic::Status>;
}
#[derive(Debug)]
pub struct StatusServiceServer<T: StatusService> {
inner: _Inner<T>,
}
struct _Inner<T>(Arc<T>, Option<tonic::Interceptor>);
impl<T: StatusService> StatusServiceServer<T> {
pub fn new(inner: T) -> Self {
let inner = Arc::new(inner);
let inner = _Inner(inner, None);
Self { inner }
}
pub fn with_interceptor(inner: T, interceptor: impl Into<tonic::Interceptor>) -> Self {
let inner = Arc::new(inner);
let inner = _Inner(inner, Some(interceptor.into()));
Self { inner }
}
}
impl<T, B> Service<http::Request<B>> for StatusServiceServer<T>
where
T: StatusService,
B: HttpBody + Send + Sync + 'static,
B::Error: Into<StdError> + Send + 'static,
{
type Response = http::Response<tonic::body::BoxBody>;
type Error = Never;
type Future = BoxFuture<Self::Response, Self::Error>;
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: http::Request<B>) -> Self::Future {
let inner = self.inner.clone();
match req.uri().path() {
"/steward.v4.StatusService/Version" => {
#[allow(non_camel_case_types)]
struct VersionSvc<T: StatusService>(pub Arc<T>);
impl<T: StatusService> tonic::server::UnaryService<super::VersionRequest> for VersionSvc<T> {
type Response = super::VersionResponse;
type Future = BoxFuture<tonic::Response<Self::Response>, tonic::Status>;
fn call(
&mut self,
request: tonic::Request<super::VersionRequest>,
) -> Self::Future {
let inner = self.0.clone();
let fut = async move { (*inner).version(request).await };
Box::pin(fut)
}
}
let inner = self.inner.clone();
let fut = async move {
let interceptor = inner.1.clone();
let inner = inner.0;
let method = VersionSvc(inner);
let codec = tonic::codec::ProstCodec::default();
let mut grpc = if let Some(interceptor) = interceptor {
tonic::server::Grpc::with_interceptor(codec, interceptor)
} else {
tonic::server::Grpc::new(codec)
};
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
_ => Box::pin(async move {
Ok(http::Response::builder()
.status(200)
.header("grpc-status", "12")
.header("content-type", "application/grpc")
.body(tonic::body::BoxBody::empty())
.unwrap())
}),
}
}
}
impl<T: StatusService> Clone for StatusServiceServer<T> {
fn clone(&self) -> Self {
let inner = self.inner.clone();
Self { inner }
}
}
impl<T: StatusService> Clone for _Inner<T> {
fn clone(&self) -> Self {
Self(self.0.clone(), self.1.clone())
}
}
impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.0)
}
}
impl<T: StatusService> tonic::transport::NamedService for StatusServiceServer<T> {
const NAME: &'static str = "steward.v4.StatusService";
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod prelude;
pub mod server;
pub mod simulate;
pub mod somm_send;
pub mod status;
pub mod tenderly;
pub mod utils;

Expand Down
22 changes: 22 additions & 0 deletions src/status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use lazy_static::lazy_static;
use tonic::{async_trait, Request, Response, Status};

use crate::proto::{self, VersionRequest, VersionResponse};

lazy_static! {
static ref STEWARD_VERSION: &'static str = env!("CARGO_PKG_VERSION");
}

pub struct StatusHandler;

#[async_trait]
impl proto::status_service_server::StatusService for StatusHandler {
async fn version(
&self,
_: Request<VersionRequest>,
) -> Result<Response<VersionResponse>, Status> {
Ok(Response::new(VersionResponse {
version: STEWARD_VERSION.to_string(),
}))
}
}
Loading

0 comments on commit 43d17a5

Please sign in to comment.