Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/build-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ jobs:
working-directory: ./cli
steps:
- uses: actions/checkout@v1
- run: cargo build
- run: cargo test
- run: |
rustup install nightly
rustup default nightly
rustup component add rustfmt
cargo build
cargo test
11 changes: 5 additions & 6 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
name = "trinsic"
version = "0.1.0"
authors = ["Trinsic <support@trinsic.id>"]
edition = "2018"
edition = "2021"

[dependencies]
tonic = "0.4"
prost = "0.7"
prost-types = "0.7"
tonic = { version = "0.6", features = ["tls", "tls-roots"] }
prost = "0.9"
prost-types = "0.9"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
okapi = { git ="https://github.com/trinsic-id/okapi", branch = "main" }
clap = { version = "~2", features = ["yaml"] }
Expand All @@ -21,8 +21,7 @@ yaml-rust = "0.3"
colored = "2"

[build-dependencies]
tonic-build = "0.4"
prost-build = "0.7"
tonic-build = { version = "0.6", features = ["prost", "rustfmt"] }

[[bin]]
name = "trinsic"
Expand Down
10 changes: 8 additions & 2 deletions cli/MAINTAINERS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Okapi CLI Maintainers
# Trinsic CLI Maintainers

Before checking in your code, please always run `cargo fmt` and `cargo clippy`.
Before checking in your code, please always run `cargo fmt` and `cargo clippy`.

Comment on lines +3 to +4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we auto format on the CI/CD pipeline?

## Tooling

- [clap](https://github.com/clap-rs/clap) - command line argument parser for Rust
- [tonic](https://github.com/hyperium/tonic) - gRPC framework
- [prost](https://github.com/danburkert/prost) - protocol buffer implementation
12 changes: 3 additions & 9 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@

## Installation

Requires [Rustup](https://www.rust-lang.org/tools/install) toolchain
Requires [Rustup](https://www.rust-lang.org/tools/install) nightly toolchain

```bash
cargo install --path .
cargo +nightly install --git https://github.com/trinsic-id/sdk trinsic
```

## Tooling

- [clap](https://github.com/clap-rs/clap) - command line argument parser for Rust
- [tonic](https://github.com/hyperium/tonic) - gRPC framework
- [prost](https://github.com/danburkert/prost) - protocol buffer implementation

## Running the CLI
## Usage

```
trinsic --help
Expand Down
26 changes: 11 additions & 15 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ fn main() {
.out_dir("./src/proto")
.format(true);

let mut prost_config = prost_build::Config::new();
prost_config.compile_well_known_types();
//.type_attribute(".", "#[derive(::serde::Serialize, ::serde::Deserialize)]");

config
.compile_well_known_types(true)
.type_attribute(
"JsonPayload",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
Expand All @@ -19,8 +16,7 @@ fn main() {
"JsonPayload.json",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
.compile_with_config(
prost_config,
.compile(
&[
"../proto/pbmse/v1/pbmse.proto",
"../proto/services/debug/v1/debug.proto",
Expand All @@ -34,39 +30,39 @@ fn main() {
)
.unwrap();

cleanup!(
move_file!(
"./src/proto/google.protobuf.rs",
"./src/proto/google/protobuf/mod.rs"
);
cleanup!("./src/proto/pbmse.v1.rs", "./src/proto/pbmse/v1/mod.rs");
cleanup!(
move_file!("./src/proto/pbmse.v1.rs", "./src/proto/pbmse/v1/mod.rs");
move_file!(
"./src/proto/services.common.v1.rs",
"./src/proto/services/common/v1/mod.rs"
);
cleanup!(
move_file!(
"./src/proto/services.debug.v1.rs",
"./src/proto/services/debug/v1/mod.rs"
);
cleanup!(
move_file!(
"./src/proto/services.provider.v1.rs",
"./src/proto/services/provider/v1/mod.rs"
);
cleanup!(
move_file!(
"./src/proto/services.trustregistry.v1.rs",
"./src/proto/services/trustregistry/v1/mod.rs"
);
cleanup!(
move_file!(
"./src/proto/services.universalwallet.v1.rs",
"./src/proto/services/universalwallet/v1/mod.rs"
);
cleanup!(
move_file!(
"./src/proto/services.verifiablecredentials.v1.rs",
"./src/proto/services/verifiablecredentials/v1/mod.rs"
);
}

#[macro_export]
macro_rules! cleanup {
macro_rules! move_file {
($from:expr,$to:expr) => {
copy($from, $to).unwrap();
remove_file($from).unwrap();
Expand Down
51 changes: 33 additions & 18 deletions cli/src/proto/services/common/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ pub enum JsonFormat {
}
#[doc = r" Generated client implementations."]
pub mod common_client {
#![allow(unused_variables, dead_code, missing_docs)]
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
use tonic::codegen::*;
#[derive(Debug, Clone)]
pub struct CommonClient<T> {
inner: tonic::client::Grpc<T>,
}
Expand All @@ -58,17 +59,43 @@ pub mod common_client {
impl<T> CommonClient<T>
where
T: tonic::client::GrpcService<tonic::body::BoxBody>,
T::ResponseBody: Body + HttpBody + Send + 'static,
T::ResponseBody: Body + Send + 'static,
T::Error: Into<StdError>,
<T::ResponseBody as HttpBody>::Error: Into<StdError> + Send,
<T::ResponseBody as Body>::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 fn with_interceptor<F>(
inner: T,
interceptor: F,
) -> CommonClient<InterceptedService<T, F>>
where
F: tonic::service::Interceptor,
T: tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
Response = http::Response<
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
>,
>,
<T as tonic::codegen::Service<http::Request<tonic::body::BoxBody>>>::Error:
Into<StdError> + Send + Sync,
{
CommonClient::new(InterceptedService::new(inner, interceptor))
}
#[doc = r" Compress requests with `gzip`."]
#[doc = r""]
#[doc = r" This requires the server to support it otherwise it might respond with an"]
#[doc = r" error."]
pub fn send_gzip(mut self) -> Self {
self.inner = self.inner.send_gzip();
self
}
#[doc = r" Enable decompressing responses with `gzip`."]
pub fn accept_gzip(mut self) -> Self {
self.inner = self.inner.accept_gzip();
self
}
pub async fn request(
&mut self,
Expand All @@ -88,16 +115,4 @@ pub mod common_client {
self.inner.unary(request.into_request(), path, codec).await
}
}
impl<T: Clone> Clone for CommonClient<T> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
}
}
}
impl<T> std::fmt::Debug for CommonClient<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "CommonClient {{ ... }}")
}
}
}
67 changes: 43 additions & 24 deletions cli/src/proto/services/debug/v1/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#[doc = r" Generated client implementations."]
pub mod debugging_client {
#![allow(unused_variables, dead_code, missing_docs)]
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
use tonic::codegen::*;
#[derive(Debug, Clone)]
pub struct DebuggingClient<T> {
inner: tonic::client::Grpc<T>,
}
Expand All @@ -19,23 +20,51 @@ pub mod debugging_client {
impl<T> DebuggingClient<T>
where
T: tonic::client::GrpcService<tonic::body::BoxBody>,
T::ResponseBody: Body + HttpBody + Send + 'static,
T::ResponseBody: Body + Send + 'static,
T::Error: Into<StdError>,
<T::ResponseBody as HttpBody>::Error: Into<StdError> + Send,
<T::ResponseBody as Body>::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 fn with_interceptor<F>(
inner: T,
interceptor: F,
) -> DebuggingClient<InterceptedService<T, F>>
where
F: tonic::service::Interceptor,
T: tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
Response = http::Response<
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
>,
>,
<T as tonic::codegen::Service<http::Request<tonic::body::BoxBody>>>::Error:
Into<StdError> + Send + Sync,
{
DebuggingClient::new(InterceptedService::new(inner, interceptor))
}
#[doc = r" Compress requests with `gzip`."]
#[doc = r""]
#[doc = r" This requires the server to support it otherwise it might respond with an"]
#[doc = r" error."]
pub fn send_gzip(mut self) -> Self {
self.inner = self.inner.send_gzip();
self
}
#[doc = r" Enable decompressing responses with `gzip`."]
pub fn accept_gzip(mut self) -> Self {
self.inner = self.inner.accept_gzip();
self
}
pub async fn call_empty(
&mut self,
request: impl tonic::IntoRequest<super::super::super::google::protobuf::Empty>,
) -> Result<tonic::Response<super::super::super::google::protobuf::Empty>, tonic::Status>
{
request: impl tonic::IntoRequest<super::super::super::super::google::protobuf::Empty>,
) -> Result<
tonic::Response<super::super::super::super::google::protobuf::Empty>,
tonic::Status,
> {
self.inner.ready().await.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
Expand All @@ -49,9 +78,11 @@ pub mod debugging_client {
}
pub async fn call_empty_auth(
&mut self,
request: impl tonic::IntoRequest<super::super::super::google::protobuf::Empty>,
) -> Result<tonic::Response<super::super::super::google::protobuf::Empty>, tonic::Status>
{
request: impl tonic::IntoRequest<super::super::super::super::google::protobuf::Empty>,
) -> Result<
tonic::Response<super::super::super::super::google::protobuf::Empty>,
tonic::Status,
> {
self.inner.ready().await.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
Expand All @@ -64,16 +95,4 @@ pub mod debugging_client {
self.inner.unary(request.into_request(), path, codec).await
}
}
impl<T: Clone> Clone for DebuggingClient<T> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
}
}
}
impl<T> std::fmt::Debug for DebuggingClient<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "DebuggingClient {{ ... }}")
}
}
}
Loading