Skip to content

Commit a75279d

Browse files
authored
Enable use of TLS in the CLI (#160)
* Correct key type * Playground * Load tls root ca tree * Finalize cli * Remove fs feature in tokio * Remove unused keys * Use nightly in CI * install and use nightly * indent * Add rustfmt
1 parent 292d541 commit a75279d

File tree

13 files changed

+278
-165
lines changed

13 files changed

+278
-165
lines changed

.github/workflows/build-rust.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@ jobs:
2525
working-directory: ./cli
2626
steps:
2727
- uses: actions/checkout@v1
28-
- run: cargo build
29-
- run: cargo test
28+
- run: |
29+
rustup install nightly
30+
rustup default nightly
31+
rustup component add rustfmt
32+
cargo build
33+
cargo test

cli/Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
name = "trinsic"
33
version = "0.1.0"
44
authors = ["Trinsic <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66

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

2323
[build-dependencies]
24-
tonic-build = "0.4"
25-
prost-build = "0.7"
24+
tonic-build = { version = "0.6", features = ["prost", "rustfmt"] }
2625

2726
[[bin]]
2827
name = "trinsic"

cli/MAINTAINERS.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
# Okapi CLI Maintainers
1+
# Trinsic CLI Maintainers
22

3-
Before checking in your code, please always run `cargo fmt` and `cargo clippy`.
3+
Before checking in your code, please always run `cargo fmt` and `cargo clippy`.
4+
5+
## Tooling
6+
7+
- [clap](https://github.com/clap-rs/clap) - command line argument parser for Rust
8+
- [tonic](https://github.com/hyperium/tonic) - gRPC framework
9+
- [prost](https://github.com/danburkert/prost) - protocol buffer implementation

cli/README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@
22

33
## Installation
44

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

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

11-
## Tooling
12-
13-
- [clap](https://github.com/clap-rs/clap) - command line argument parser for Rust
14-
- [tonic](https://github.com/hyperium/tonic) - gRPC framework
15-
- [prost](https://github.com/danburkert/prost) - protocol buffer implementation
16-
17-
## Running the CLI
11+
## Usage
1812

1913
```
2014
trinsic --help

cli/build.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ fn main() {
66
.out_dir("./src/proto")
77
.format(true);
88

9-
let mut prost_config = prost_build::Config::new();
10-
prost_config.compile_well_known_types();
11-
//.type_attribute(".", "#[derive(::serde::Serialize, ::serde::Deserialize)]");
12-
139
config
10+
.compile_well_known_types(true)
1411
.type_attribute(
1512
"JsonPayload",
1613
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
@@ -19,8 +16,7 @@ fn main() {
1916
"JsonPayload.json",
2017
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
2118
)
22-
.compile_with_config(
23-
prost_config,
19+
.compile(
2420
&[
2521
"../proto/pbmse/v1/pbmse.proto",
2622
"../proto/services/debug/v1/debug.proto",
@@ -34,39 +30,39 @@ fn main() {
3430
)
3531
.unwrap();
3632

37-
cleanup!(
33+
move_file!(
3834
"./src/proto/google.protobuf.rs",
3935
"./src/proto/google/protobuf/mod.rs"
4036
);
41-
cleanup!("./src/proto/pbmse.v1.rs", "./src/proto/pbmse/v1/mod.rs");
42-
cleanup!(
37+
move_file!("./src/proto/pbmse.v1.rs", "./src/proto/pbmse/v1/mod.rs");
38+
move_file!(
4339
"./src/proto/services.common.v1.rs",
4440
"./src/proto/services/common/v1/mod.rs"
4541
);
46-
cleanup!(
42+
move_file!(
4743
"./src/proto/services.debug.v1.rs",
4844
"./src/proto/services/debug/v1/mod.rs"
4945
);
50-
cleanup!(
46+
move_file!(
5147
"./src/proto/services.provider.v1.rs",
5248
"./src/proto/services/provider/v1/mod.rs"
5349
);
54-
cleanup!(
50+
move_file!(
5551
"./src/proto/services.trustregistry.v1.rs",
5652
"./src/proto/services/trustregistry/v1/mod.rs"
5753
);
58-
cleanup!(
54+
move_file!(
5955
"./src/proto/services.universalwallet.v1.rs",
6056
"./src/proto/services/universalwallet/v1/mod.rs"
6157
);
62-
cleanup!(
58+
move_file!(
6359
"./src/proto/services.verifiablecredentials.v1.rs",
6460
"./src/proto/services/verifiablecredentials/v1/mod.rs"
6561
);
6662
}
6763

6864
#[macro_export]
69-
macro_rules! cleanup {
65+
macro_rules! move_file {
7066
($from:expr,$to:expr) => {
7167
copy($from, $to).unwrap();
7268
remove_file($from).unwrap();

cli/src/proto/services/common/v1/mod.rs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ pub enum JsonFormat {
3939
}
4040
#[doc = r" Generated client implementations."]
4141
pub mod common_client {
42-
#![allow(unused_variables, dead_code, missing_docs)]
42+
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
4343
use tonic::codegen::*;
44+
#[derive(Debug, Clone)]
4445
pub struct CommonClient<T> {
4546
inner: tonic::client::Grpc<T>,
4647
}
@@ -58,17 +59,43 @@ pub mod common_client {
5859
impl<T> CommonClient<T>
5960
where
6061
T: tonic::client::GrpcService<tonic::body::BoxBody>,
61-
T::ResponseBody: Body + HttpBody + Send + 'static,
62+
T::ResponseBody: Body + Send + 'static,
6263
T::Error: Into<StdError>,
63-
<T::ResponseBody as HttpBody>::Error: Into<StdError> + Send,
64+
<T::ResponseBody as Body>::Error: Into<StdError> + Send,
6465
{
6566
pub fn new(inner: T) -> Self {
6667
let inner = tonic::client::Grpc::new(inner);
6768
Self { inner }
6869
}
69-
pub fn with_interceptor(inner: T, interceptor: impl Into<tonic::Interceptor>) -> Self {
70-
let inner = tonic::client::Grpc::with_interceptor(inner, interceptor);
71-
Self { inner }
70+
pub fn with_interceptor<F>(
71+
inner: T,
72+
interceptor: F,
73+
) -> CommonClient<InterceptedService<T, F>>
74+
where
75+
F: tonic::service::Interceptor,
76+
T: tonic::codegen::Service<
77+
http::Request<tonic::body::BoxBody>,
78+
Response = http::Response<
79+
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
80+
>,
81+
>,
82+
<T as tonic::codegen::Service<http::Request<tonic::body::BoxBody>>>::Error:
83+
Into<StdError> + Send + Sync,
84+
{
85+
CommonClient::new(InterceptedService::new(inner, interceptor))
86+
}
87+
#[doc = r" Compress requests with `gzip`."]
88+
#[doc = r""]
89+
#[doc = r" This requires the server to support it otherwise it might respond with an"]
90+
#[doc = r" error."]
91+
pub fn send_gzip(mut self) -> Self {
92+
self.inner = self.inner.send_gzip();
93+
self
94+
}
95+
#[doc = r" Enable decompressing responses with `gzip`."]
96+
pub fn accept_gzip(mut self) -> Self {
97+
self.inner = self.inner.accept_gzip();
98+
self
7299
}
73100
pub async fn request(
74101
&mut self,
@@ -88,16 +115,4 @@ pub mod common_client {
88115
self.inner.unary(request.into_request(), path, codec).await
89116
}
90117
}
91-
impl<T: Clone> Clone for CommonClient<T> {
92-
fn clone(&self) -> Self {
93-
Self {
94-
inner: self.inner.clone(),
95-
}
96-
}
97-
}
98-
impl<T> std::fmt::Debug for CommonClient<T> {
99-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
100-
write!(f, "CommonClient {{ ... }}")
101-
}
102-
}
103118
}
Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#[doc = r" Generated client implementations."]
22
pub mod debugging_client {
3-
#![allow(unused_variables, dead_code, missing_docs)]
3+
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
44
use tonic::codegen::*;
5+
#[derive(Debug, Clone)]
56
pub struct DebuggingClient<T> {
67
inner: tonic::client::Grpc<T>,
78
}
@@ -19,23 +20,51 @@ pub mod debugging_client {
1920
impl<T> DebuggingClient<T>
2021
where
2122
T: tonic::client::GrpcService<tonic::body::BoxBody>,
22-
T::ResponseBody: Body + HttpBody + Send + 'static,
23+
T::ResponseBody: Body + Send + 'static,
2324
T::Error: Into<StdError>,
24-
<T::ResponseBody as HttpBody>::Error: Into<StdError> + Send,
25+
<T::ResponseBody as Body>::Error: Into<StdError> + Send,
2526
{
2627
pub fn new(inner: T) -> Self {
2728
let inner = tonic::client::Grpc::new(inner);
2829
Self { inner }
2930
}
30-
pub fn with_interceptor(inner: T, interceptor: impl Into<tonic::Interceptor>) -> Self {
31-
let inner = tonic::client::Grpc::with_interceptor(inner, interceptor);
32-
Self { inner }
31+
pub fn with_interceptor<F>(
32+
inner: T,
33+
interceptor: F,
34+
) -> DebuggingClient<InterceptedService<T, F>>
35+
where
36+
F: tonic::service::Interceptor,
37+
T: tonic::codegen::Service<
38+
http::Request<tonic::body::BoxBody>,
39+
Response = http::Response<
40+
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
41+
>,
42+
>,
43+
<T as tonic::codegen::Service<http::Request<tonic::body::BoxBody>>>::Error:
44+
Into<StdError> + Send + Sync,
45+
{
46+
DebuggingClient::new(InterceptedService::new(inner, interceptor))
47+
}
48+
#[doc = r" Compress requests with `gzip`."]
49+
#[doc = r""]
50+
#[doc = r" This requires the server to support it otherwise it might respond with an"]
51+
#[doc = r" error."]
52+
pub fn send_gzip(mut self) -> Self {
53+
self.inner = self.inner.send_gzip();
54+
self
55+
}
56+
#[doc = r" Enable decompressing responses with `gzip`."]
57+
pub fn accept_gzip(mut self) -> Self {
58+
self.inner = self.inner.accept_gzip();
59+
self
3360
}
3461
pub async fn call_empty(
3562
&mut self,
36-
request: impl tonic::IntoRequest<super::super::super::google::protobuf::Empty>,
37-
) -> Result<tonic::Response<super::super::super::google::protobuf::Empty>, tonic::Status>
38-
{
63+
request: impl tonic::IntoRequest<super::super::super::super::google::protobuf::Empty>,
64+
) -> Result<
65+
tonic::Response<super::super::super::super::google::protobuf::Empty>,
66+
tonic::Status,
67+
> {
3968
self.inner.ready().await.map_err(|e| {
4069
tonic::Status::new(
4170
tonic::Code::Unknown,
@@ -49,9 +78,11 @@ pub mod debugging_client {
4978
}
5079
pub async fn call_empty_auth(
5180
&mut self,
52-
request: impl tonic::IntoRequest<super::super::super::google::protobuf::Empty>,
53-
) -> Result<tonic::Response<super::super::super::google::protobuf::Empty>, tonic::Status>
54-
{
81+
request: impl tonic::IntoRequest<super::super::super::super::google::protobuf::Empty>,
82+
) -> Result<
83+
tonic::Response<super::super::super::super::google::protobuf::Empty>,
84+
tonic::Status,
85+
> {
5586
self.inner.ready().await.map_err(|e| {
5687
tonic::Status::new(
5788
tonic::Code::Unknown,
@@ -64,16 +95,4 @@ pub mod debugging_client {
6495
self.inner.unary(request.into_request(), path, codec).await
6596
}
6697
}
67-
impl<T: Clone> Clone for DebuggingClient<T> {
68-
fn clone(&self) -> Self {
69-
Self {
70-
inner: self.inner.clone(),
71-
}
72-
}
73-
}
74-
impl<T> std::fmt::Debug for DebuggingClient<T> {
75-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76-
write!(f, "DebuggingClient {{ ... }}")
77-
}
78-
}
7998
}

0 commit comments

Comments
 (0)