Skip to content
Merged
865 changes: 368 additions & 497 deletions cli/Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ yaml-rust = "0.3"
colored = "2"
blake3 = "1.2"
bytes = "1.1"
indexmap = "1.8"

[build-dependencies]
tonic-build = { version = "0.6", features = ["prost", "rustfmt"] }
Expand Down
13 changes: 10 additions & 3 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ fn main() {
config
.compile_well_known_types(true)
.type_attribute(
"JsonPayload",
"ServiceOptions",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
.field_attribute("JsonPayload.json", "#[serde(flatten)]")
.type_attribute(
"JsonPayload.json",
".services",
"#[derive(::serde::Serialize, ::serde::Deserialize)]",
)
// .field_attribute(
// "ServiceOptions.auth_token",
// "#[serde(skip_serializing_if = \"String::is_empty\")]",
// )
// .type_attribute(
// "JsonPayload.json",
// "#[derive(::serde::Serialize, ::serde::Deserialize)]",
// )
.compile(
&[
"../proto/pbmse/v1/pbmse.proto",
Expand Down
78 changes: 37 additions & 41 deletions cli/src/cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,27 @@ subcommands:
takes_value: true
required: false
long: server-endpoint
short: e
- server-port:
value_name: NUMBER
help: "(Optional) Port of the server endpoint. (default: 443)"
takes_value: true
required: false
long: server-port
short: p
- server-use-tls:
value_name: BOOL
help: "(Optional) Indicates if TLS should be used. (default: true)"
takes_value: true
required: false
long: server-use-tls
- profile-default:
long: profile-default
- auth-token:
long: auth-token
short: a
value_name: NAME
help: (Optional) Name of the profile to set as default
help: (Optional) Sets the auth token for outgoing requests
takes_value: true
required: false
- show:
long: show
takes_value: false
required: false
help: Show the current configuration file
- account:
about: Account Service
subcommands:
Expand Down Expand Up @@ -72,19 +70,12 @@ subcommands:
help: (Optional) Invitation code provided by authorized entity
takes_value: true
required: false
- alias:
long: alias
value_name: PROFILE_NAME
help: >-
(Required) Alias of the local profile to use to store
authentication data
- ecosystem:
long: ecosystem
short: e
takes_value: true
required: true
- default:
long: default
takes_value: false
required: false
help: (Optional) Set this profile as default
help: (Optional) The ecosystem name or id to sign in
- info:
about: Show account information
- wallet:
Expand Down Expand Up @@ -175,6 +166,13 @@ subcommands:
value_name: FILE
help: The file with JSON values of the credential subject
takes_value: true
- out:
long: out
short: o
value_name: OUTPUT_FILE
help: (Optional) Output file to store the issued credential
takes_value: true
required: false
- update-status:
about: Update the credential status (revocation) of an issued credential
args:
Expand All @@ -200,26 +198,33 @@ subcommands:
takes_value: true
required: true
- create-proof:
about: Create a proof
about: Create a proof of signature from a document in the user's wallet or a file
args:
- reveal-document:
long: reveal-document
value_name: JSONLD_FRAME_FILE
help: Document
- reveal-document-file:
long: reveal-document-file
value_name: REVEAL FRAME FILE
help: (Optional) Input document that contains valid JSON-LD frame to be used for creating the proof
takes_value: true
required: true
- document-id:
long: document-id
required: false
- item-id:
long: item-id
value_name: STRING
help: Document id
help: Item ID of a document in the user's wallet
takes_value: true
required: true
required: false
- document-file:
long: document-file
value_name: FILE
help: File that contains a signed document
takes_value: true
required: false
- out:
long: out
short: o
value_name: OUTPUT_FILE
help: output location for created_proof
help: Output file to store the generated proof
takes_value: true
required: true
required: false
- verify-proof:
about: Verify a proof
args:
Expand Down Expand Up @@ -294,7 +299,7 @@ subcommands:
value_name: SQL query
help: |
The SQL query to search the registry.
Default value is "SELECT * FROM c".
Default value is "SELECT c.data, c.id, c.type FROM c".
takes_value: true
required: true
- check-issuer:
Expand Down Expand Up @@ -469,15 +474,6 @@ subcommands:
takes_value: true
required: true
args:
- profile:
long: alias
short: a
value_name: NAME
help: >-
(Optional) Account alias to use for authentication. If not set, it will
use the default configured.
takes_value: true
required: false
- debug:
long: debug
short: d
Expand Down
72 changes: 72 additions & 0 deletions cli/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use std::fmt::Display;

use serde::{Deserialize, Serialize};
use tonic::Status;

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub(crate) enum Error {
IOError,
SerializationError,
APIError { code: String, message: String },
MissingArguments,
ConnectionError,
InvalidArgument(String),
UnknownCommand,
}

impl From<toml::ser::Error> for Error {
fn from(_: toml::ser::Error) -> Self {
Error::SerializationError
}
}

impl From<toml::de::Error> for Error {
fn from(_: toml::de::Error) -> Self {
Error::SerializationError
}
}

impl From<tonic::codegen::http::uri::InvalidUri> for Error {
fn from(_: tonic::codegen::http::uri::InvalidUri) -> Self {
Error::InvalidArgument("invalid server uri".to_string())
}
}

impl From<tonic::transport::Error> for Error {
fn from(_: tonic::transport::Error) -> Self {
Error::ConnectionError
}
}

impl From<std::io::Error> for Error {
fn from(_: std::io::Error) -> Self {
Error::IOError
}
}

impl From<serde_json::Error> for Error {
fn from(_: serde_json::Error) -> Self {
Error::SerializationError
}
}

impl From<prost::DecodeError> for Error {
fn from(_: prost::DecodeError) -> Self {
Error::SerializationError
}
}

impl From<Status> for Error {
fn from(status: Status) -> Self {
Error::APIError {
code: status.code().to_string(),
message: status.message().to_string(),
}
}
}

impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("{:#?}", self))
}
}
6 changes: 1 addition & 5 deletions cli/src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#[macro_export]
macro_rules! grpc_channel {
($x:expr) => {
Channel::from_shared(&$x.server)
.unwrap()
.connect()
.await
.expect("Unable to connect to server")
Channel::from_shared(&$x.options)?.connect().await?
};
}

Expand Down
Loading