Skip to content

Commit 87ddfe1

Browse files
committed
Add /version endpoint
This endpoint allows clients to check the version of the VSS API that the server is serving. It also serves as a health check.
1 parent 5d90568 commit 87ddfe1

4 files changed

Lines changed: 65 additions & 1 deletion

File tree

.github/workflows/build-and-deploy-rust.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ jobs:
4545
run: |
4646
sleep 5
4747
48+
[[ $(curl -f -s http://localhost:8080/vss/version | xxd -p) == "0801" ]] || { echo "Version check failed"; exit 1; }
49+
4850
# Put request with store='storeId' and key=k1
4951
hex=0A0773746F726549641A150A026B3110FFFFFFFFFFFFFFFFFF011A046B317631
5052
curl -f --data-binary "$(echo "$hex" | xxd -r -p)" http://localhost:8080/vss/putObjects

proto/vss.proto

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ package vss;
33
option java_multiple_files = true;
44
option java_package = "org.vss";
55

6+
// Server response on the `/version` endpoint.
7+
message VersionResponse {
8+
9+
// The API version supported by the server.
10+
Version version = 1;
11+
}
12+
13+
// Versions of the VSS API.
14+
enum Version {
15+
16+
// Default protobuf Enum value. Will not be used as `Version` by server.
17+
VUNKNOWN = 0;
18+
19+
// The initial version of the VSS API.
20+
V1 = 1;
21+
}
22+
623
// Request payload to be used for `GetObject` API call to server.
724
message GetObjectRequest {
825

rust/api/src/types.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/// Server response on the `/version` endpoint.
2+
#[allow(clippy::derive_partial_eq_without_eq)]
3+
#[derive(Clone, PartialEq, ::prost::Message)]
4+
pub struct VersionResponse {
5+
/// The API version supported by the server.
6+
#[prost(enumeration = "Version", tag = "1")]
7+
pub version: i32,
8+
}
19
/// Request payload to be used for `GetObject` API call to server.
210
#[allow(clippy::derive_partial_eq_without_eq)]
311
#[derive(Clone, PartialEq, ::prost::Message)]
@@ -331,6 +339,35 @@ pub struct PlaintextBlob {
331339
#[prost(int64, tag = "2")]
332340
pub version: i64,
333341
}
342+
/// Versions of the VSS API.
343+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
344+
#[repr(i32)]
345+
pub enum Version {
346+
/// Default protobuf Enum value. Will not be used as `Version` by server.
347+
Vunknown = 0,
348+
/// The initial version of the VSS API.
349+
V1 = 1,
350+
}
351+
impl Version {
352+
/// String value of the enum field names used in the ProtoBuf definition.
353+
///
354+
/// The values are not transformed in any way and thus are considered stable
355+
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
356+
pub fn as_str_name(&self) -> &'static str {
357+
match self {
358+
Version::Vunknown => "VUNKNOWN",
359+
Version::V1 => "V1",
360+
}
361+
}
362+
/// Creates an enum from field names used in the ProtoBuf definition.
363+
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
364+
match value {
365+
"VUNKNOWN" => Some(Self::Vunknown),
366+
"V1" => Some(Self::V1),
367+
_ => None,
368+
}
369+
}
370+
}
334371
/// ErrorCodes to be used in `ErrorResponse`
335372
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
336373
#[repr(i32)]

rust/server/src/vss_service.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use api::kv_store::KvStore;
1212
use api::types::{
1313
DeleteObjectRequest, DeleteObjectResponse, ErrorCode, ErrorResponse, GetObjectRequest,
1414
GetObjectResponse, ListKeyVersionsRequest, ListKeyVersionsResponse, PutObjectRequest,
15-
PutObjectResponse,
15+
PutObjectResponse, Version, VersionResponse,
1616
};
1717
use std::future::Future;
1818
use std::pin::Pin;
@@ -80,6 +80,14 @@ impl Service<Request<Incoming>> for VssService {
8080
let prefix_stripped_path = path.strip_prefix(BASE_PATH_PREFIX).unwrap_or_default();
8181

8282
match prefix_stripped_path {
83+
"/version" => {
84+
let response = VersionResponse { version: Version::V1.into() };
85+
let response = Response::builder()
86+
.body(Full::new(Bytes::from(response.encode_to_vec())))
87+
// unwrap safety: body only errors when previous chained calls failed.
88+
.unwrap();
89+
Ok(response)
90+
},
8391
"/getObject" => {
8492
handle_request(
8593
store,

0 commit comments

Comments
 (0)