Skip to content

Commit ebd4995

Browse files
authored
[cli] API hardening, eliminate panics, results display, missing features (#486)
* Use proto options object * Simplify config persistance * Sign in works * Update oberon * Use global output to print out data * Remove warnings * Update all apis to use new method * Simplify map use * Update template service * Move provider to new api * trust registry update * Update config to new api * Fix config path
1 parent b7cb49e commit ebd4995

File tree

32 files changed

+1239
-1351
lines changed

32 files changed

+1239
-1351
lines changed

cli/Cargo.lock

Lines changed: 368 additions & 497 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ yaml-rust = "0.3"
2323
colored = "2"
2424
blake3 = "1.2"
2525
bytes = "1.1"
26+
indexmap = "1.8"
2627

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

cli/build.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@ fn main() {
99
config
1010
.compile_well_known_types(true)
1111
.type_attribute(
12-
"JsonPayload",
12+
"ServiceOptions",
1313
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
1414
)
15-
.field_attribute("JsonPayload.json", "#[serde(flatten)]")
1615
.type_attribute(
17-
"JsonPayload.json",
16+
".services",
1817
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
1918
)
19+
// .field_attribute(
20+
// "ServiceOptions.auth_token",
21+
// "#[serde(skip_serializing_if = \"String::is_empty\")]",
22+
// )
23+
// .type_attribute(
24+
// "JsonPayload.json",
25+
// "#[derive(::serde::Serialize, ::serde::Deserialize)]",
26+
// )
2027
.compile(
2128
&[
2229
"../proto/pbmse/v1/pbmse.proto",

cli/src/cli.yaml

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,27 @@ subcommands:
1717
takes_value: true
1818
required: false
1919
long: server-endpoint
20+
short: e
2021
- server-port:
2122
value_name: NUMBER
2223
help: "(Optional) Port of the server endpoint. (default: 443)"
2324
takes_value: true
2425
required: false
2526
long: server-port
27+
short: p
2628
- server-use-tls:
2729
value_name: BOOL
2830
help: "(Optional) Indicates if TLS should be used. (default: true)"
2931
takes_value: true
3032
required: false
3133
long: server-use-tls
32-
- profile-default:
33-
long: profile-default
34+
- auth-token:
35+
long: auth-token
36+
short: a
3437
value_name: NAME
35-
help: (Optional) Name of the profile to set as default
38+
help: (Optional) Sets the auth token for outgoing requests
3639
takes_value: true
3740
required: false
38-
- show:
39-
long: show
40-
takes_value: false
41-
required: false
42-
help: Show the current configuration file
4341
- account:
4442
about: Account Service
4543
subcommands:
@@ -72,19 +70,12 @@ subcommands:
7270
help: (Optional) Invitation code provided by authorized entity
7371
takes_value: true
7472
required: false
75-
- alias:
76-
long: alias
77-
value_name: PROFILE_NAME
78-
help: >-
79-
(Required) Alias of the local profile to use to store
80-
authentication data
73+
- ecosystem:
74+
long: ecosystem
75+
short: e
8176
takes_value: true
82-
required: true
83-
- default:
84-
long: default
85-
takes_value: false
8677
required: false
87-
help: (Optional) Set this profile as default
78+
help: (Optional) The ecosystem name or id to sign in
8879
- info:
8980
about: Show account information
9081
- wallet:
@@ -175,6 +166,13 @@ subcommands:
175166
value_name: FILE
176167
help: The file with JSON values of the credential subject
177168
takes_value: true
169+
- out:
170+
long: out
171+
short: o
172+
value_name: OUTPUT_FILE
173+
help: (Optional) Output file to store the issued credential
174+
takes_value: true
175+
required: false
178176
- update-status:
179177
about: Update the credential status (revocation) of an issued credential
180178
args:
@@ -200,26 +198,33 @@ subcommands:
200198
takes_value: true
201199
required: true
202200
- create-proof:
203-
about: Create a proof
201+
about: Create a proof of signature from a document in the user's wallet or a file
204202
args:
205-
- reveal-document:
206-
long: reveal-document
207-
value_name: JSONLD_FRAME_FILE
208-
help: Document
203+
- reveal-document-file:
204+
long: reveal-document-file
205+
value_name: REVEAL FRAME FILE
206+
help: (Optional) Input document that contains valid JSON-LD frame to be used for creating the proof
209207
takes_value: true
210-
required: true
211-
- document-id:
212-
long: document-id
208+
required: false
209+
- item-id:
210+
long: item-id
213211
value_name: STRING
214-
help: Document id
212+
help: Item ID of a document in the user's wallet
215213
takes_value: true
216-
required: true
214+
required: false
215+
- document-file:
216+
long: document-file
217+
value_name: FILE
218+
help: File that contains a signed document
219+
takes_value: true
220+
required: false
217221
- out:
218222
long: out
223+
short: o
219224
value_name: OUTPUT_FILE
220-
help: output location for created_proof
225+
help: Output file to store the generated proof
221226
takes_value: true
222-
required: true
227+
required: false
223228
- verify-proof:
224229
about: Verify a proof
225230
args:
@@ -294,7 +299,7 @@ subcommands:
294299
value_name: SQL query
295300
help: |
296301
The SQL query to search the registry.
297-
Default value is "SELECT * FROM c".
302+
Default value is "SELECT c.data, c.id, c.type FROM c".
298303
takes_value: true
299304
required: true
300305
- check-issuer:
@@ -469,15 +474,6 @@ subcommands:
469474
takes_value: true
470475
required: true
471476
args:
472-
- profile:
473-
long: alias
474-
short: a
475-
value_name: NAME
476-
help: >-
477-
(Optional) Account alias to use for authentication. If not set, it will
478-
use the default configured.
479-
takes_value: true
480-
required: false
481477
- debug:
482478
long: debug
483479
short: d

cli/src/error.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
use std::fmt::Display;
2+
3+
use serde::{Deserialize, Serialize};
4+
use tonic::Status;
5+
6+
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
7+
pub(crate) enum Error {
8+
IOError,
9+
SerializationError,
10+
APIError { code: String, message: String },
11+
MissingArguments,
12+
ConnectionError,
13+
InvalidArgument(String),
14+
UnknownCommand,
15+
}
16+
17+
impl From<toml::ser::Error> for Error {
18+
fn from(_: toml::ser::Error) -> Self {
19+
Error::SerializationError
20+
}
21+
}
22+
23+
impl From<toml::de::Error> for Error {
24+
fn from(_: toml::de::Error) -> Self {
25+
Error::SerializationError
26+
}
27+
}
28+
29+
impl From<tonic::codegen::http::uri::InvalidUri> for Error {
30+
fn from(_: tonic::codegen::http::uri::InvalidUri) -> Self {
31+
Error::InvalidArgument("invalid server uri".to_string())
32+
}
33+
}
34+
35+
impl From<tonic::transport::Error> for Error {
36+
fn from(_: tonic::transport::Error) -> Self {
37+
Error::ConnectionError
38+
}
39+
}
40+
41+
impl From<std::io::Error> for Error {
42+
fn from(_: std::io::Error) -> Self {
43+
Error::IOError
44+
}
45+
}
46+
47+
impl From<serde_json::Error> for Error {
48+
fn from(_: serde_json::Error) -> Self {
49+
Error::SerializationError
50+
}
51+
}
52+
53+
impl From<prost::DecodeError> for Error {
54+
fn from(_: prost::DecodeError) -> Self {
55+
Error::SerializationError
56+
}
57+
}
58+
59+
impl From<Status> for Error {
60+
fn from(status: Status) -> Self {
61+
Error::APIError {
62+
code: status.code().to_string(),
63+
message: status.message().to_string(),
64+
}
65+
}
66+
}
67+
68+
impl Display for Error {
69+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70+
f.write_fmt(format_args!("{:#?}", self))
71+
}
72+
}

cli/src/macros.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
#[macro_export]
22
macro_rules! grpc_channel {
33
($x:expr) => {
4-
Channel::from_shared(&$x.server)
5-
.unwrap()
6-
.connect()
7-
.await
8-
.expect("Unable to connect to server")
4+
Channel::from_shared(&$x.options)?.connect().await?
95
};
106
}
117

0 commit comments

Comments
 (0)