Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/164/json output #240

Closed
wants to merge 12 commits into from
Closed
2 changes: 1 addition & 1 deletion crates/agent/src/modules/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct DidEndpoint {
pub did: String,

/// The endpoint url
pub endpoint: String,
pub endpoint: Option<String>,
}

/// Options that are supplied when querying a wallet for DIDs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ impl<'a> CreateCredentialDefinition<'a> {
"Created".green(),
String::from(&credential_definition.credential_definition_id).green()
);
copy!("{}", credential_definition.credential_definition_id);
copy!("{}", &credential_definition.credential_definition_id);
log_json!(
{"credential_definition_id": &credential_definition.credential_definition_id}
);
Ok(credential_definition)
}
}
3 changes: 2 additions & 1 deletion crates/automations/src/automations/credential_offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl CredentialOfferAutomation {
/// 1. Create a connection
/// 2. Register the schema
/// 3. Register the credential definition
/// 4. Offer the credentail to the connection id
/// 4. Offer the credential to the connection id
///
/// # Errors
///
Expand Down Expand Up @@ -77,6 +77,7 @@ impl CredentialOfferAutomation {

log_trace!("Automation completed and offered a credential");
log_trace!("{:#?}", credential_offer_response);
log_json!(credential_offer_response);
Ok(())
}
}
8 changes: 6 additions & 2 deletions crates/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ pub struct Cli {
pub copy: bool,

/// Whether the output should be quiet
#[clap(long, short, help = HelpStrings::Quiet, conflicts_with = "verbose")]
#[clap(long, short, help = HelpStrings::Quiet, conflicts_with = "verbose", conflicts_with = "json")]
pub quiet: bool,

/// Whether the output should be quiet
#[clap(long, short = 'j', help = HelpStrings::Quiet, conflicts_with = "verbose", conflicts_with = "quiet")]
pub json: bool,

/// Which config path to use instead of the default one
#[clap(long, short = 'o', help = HelpStrings::Config)]
pub config: Option<PathBuf>,
Expand All @@ -51,7 +55,7 @@ pub struct Cli {
pub environment: String,

/// Whether more verbose output should be printed
#[clap(long, short='v', help = HelpStrings::Verbose, parse(from_occurrences), conflicts_with = "quiet")]
#[clap(long, short='v', help = HelpStrings::Verbose, parse(from_occurrences), conflicts_with = "quiet", conflicts_with = "json")]
pub verbose: usize,
morrieinmaas marked this conversation as resolved.
Show resolved Hide resolved

/// The main cli subcommands
Expand Down
5 changes: 3 additions & 2 deletions crates/cli/src/modules/basic_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use siera_agent::modules::basic_message::{BasicMessageModule, SendBasicMessageOp
#[derive(Args)]
#[clap(about = HelpStrings::Message)]
pub struct BasicMessageOptions {
/// The connection id to which to send the connectoon to
/// The connection id to which to send the connection to
#[clap(short = 'i', long, help=HelpStrings::MessageId)]
connection_id: String,

Expand All @@ -29,6 +29,7 @@ pub async fn parse_basic_message_args(
};
agent.send_message(send_options).await.map(|_| {
loader.stop();
log!("Successfully sent message")
log!("Successfully sent message");
log_json!({"status": "success"});
})
}
8 changes: 6 additions & 2 deletions crates/cli/src/modules/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub async fn parse_connection_args(
} else {
log_info!("Another agent can use this URL to accept your invitation:");
log!("{}", &response.invitation_url);
log_json!({ "invitation_url": &response.invitation_url });
}
copy!("{}", response.invitation_url);
})
Expand All @@ -137,6 +138,7 @@ pub async fn parse_connection_args(
log_debug!("{}", pretty_stringify_obj(&connection));
log_info!("Fetched connection id:");
log!("{}", connection.id);
log_json!({ "connection_id": connection.id });
})
}
ConnectionSubcommands::List {
Expand All @@ -152,7 +154,8 @@ pub async fn parse_connection_args(
Some(i) => agent.get_by_id(i.clone()).await.map(|connection| {
loader.stop();
copy!("{}", pretty_stringify_obj(&connection));
log!("{}", pretty_stringify_obj(connection));
log!("{}", pretty_stringify_obj(&connection));
log_json!({ "connection": connection })
}),
None => {
let options = ConnectionGetAllOptions {
Expand All @@ -171,7 +174,8 @@ pub async fn parse_connection_args(
agent.get_all(options).await.map(|connections| {
loader.stop();
copy!("{}", pretty_stringify_obj(&connections));
log!("{}", pretty_stringify_obj(connections));
log!("{}", pretty_stringify_obj(&connections));
log_json!({ "connections": connections })
})
}
},
Expand Down
5 changes: 3 additions & 2 deletions crates/cli/src/modules/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ pub async fn parse_credentials_args(
agent.send_offer(options).await.map(|cred| {
loader.stop();
log_debug!("{}", pretty_stringify_obj(&cred));
log_info!("Successefully offered a credential. Credential exchange id: ",);
log!("{}", cred.credential_exchange_id);
log_info!("Successfully offered a credential. Credential exchange id: ",);
morrieinmaas marked this conversation as resolved.
Show resolved Hide resolved
copy!("{}", cred.credential_exchange_id);
log_json!({ "credential_exchange_id": cred.credential_exchange_id });
})
}
}
Expand Down
7 changes: 5 additions & 2 deletions crates/cli/src/modules/credential_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub async fn parse_credential_definition_args(
copy!("{}", cred_def.credential_definition_id);
log_info!("Created credential definition with id:");
log!("{}", cred_def.credential_definition_id);
log_json!({ "credential_definition_id": cred_def.credential_definition_id })
})
}
CredentialDefinitionSubcommands::List { id } => match id {
Expand All @@ -87,9 +88,10 @@ pub async fn parse_credential_definition_args(
"tag": cred_def.tag,
"ver": cred_def.ver,
});
log_debug!("{}", pretty_stringify_obj(cred_def));
log_debug!("{}", pretty_stringify_obj(&cred_def));
copy!("{}", pretty_stringify_obj(&loggable));
log!("{}", pretty_stringify_obj(loggable));
log!("{}", pretty_stringify_obj(&loggable));
log_json!({ "credential_definition": loggable })
}),

None => agent.get_all().await.map(|cred_defs| {
Expand All @@ -99,6 +101,7 @@ pub async fn parse_credential_definition_args(
.iter()
.for_each(|x| log!("{}", x));
log_info!("Successfully fetched credential definition IDs",);
log_json!({ "credential_definitions": cred_defs });
}),
},
}
Expand Down
1 change: 1 addition & 0 deletions crates/cli/src/modules/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ pub async fn parse_features_args(agent: impl FeatureModule + Send + Sync) -> Res
features.disclose.protocols.iter().for_each(|p| {
log!("{}", p.pid);
});
log_json!({ "features": features.disclose.protocols });
})
}
6 changes: 4 additions & 2 deletions crates/cli/src/modules/multitenancy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ pub async fn parse_multitenancy_args(
MultitenancySubcommands::Create {} => agent.create().await.map(|response| {
loader.stop();
copy!("{}", response.wallet_id);
log!("{}", pretty_stringify_obj(response));
log!("{}", pretty_stringify_obj(&response));
log_json!(response);
}),
MultitenancySubcommands::Remove { wallet_id } => {
agent.remove(wallet_id.clone()).await?;
loader.stop();
log!("Successfully removed wallet with id: {}", wallet_id);
log!("Successfully removed wallet with id: {}", &wallet_id);
log_json!({ "wallet_id": wallet_id });
Ok(())
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/cli/src/modules/oob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub async fn parse_oob_args(
} else {
log_info!("Another agent can use this URL to accept your invitation:\n");
log!("{}", &response.invitation_url);
log_json!({ "invitation_url": response.invitation_url })
}
copy!("{}", response.invitation_url);
})
Expand All @@ -98,7 +99,8 @@ pub async fn parse_oob_args(
.map(|connection| {
log_debug!("{}", pretty_stringify_obj(&connection));
log_info!("Fetched connection id:");
log!("{}", connection.connection_id);
log!("{}", &connection.connection_id);
log_json!({ "connection_id": connection.connection_id})
})
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/cli/src/modules/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub enum ProofSubcommands {
},
}

/// Subcoammnd Proof parser
/// Subcommand Proof parser
pub async fn parse_proof_args(
commands: &ProofSubcommands,
agent: impl ProofModule + Send + Sync,
Expand Down Expand Up @@ -75,8 +75,9 @@ pub async fn parse_proof_args(
.await
.map(|proof| {
log_debug!("{}", pretty_stringify_obj(&proof));
log_info!("Successefully requested a proof. proof exchange id: ",);
log_info!("Successfully requested a proof. proof exchange id: ",);
log!("{}", &proof.presentation_exchange_id);
log_json!({ "presentation_exchange_id": &proof.presentation_exchange_id });
copy!("{}", &proof.presentation_exchange_id);
})?;
loader.stop();
Expand Down
4 changes: 3 additions & 1 deletion crates/cli/src/modules/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ pub async fn parse_schema_args(
.into_iter()
.for_each(|name| log_info!("- {}", name));
log_info!("Schema id:");
log!("{}", schema.id);
log!("{}", &schema.id);
log_json!({ "schema_id": &schema.id });
copy!("{}", schema.id);
})
}
Expand All @@ -85,6 +86,7 @@ pub async fn parse_schema_args(
loader.stop();
schemas.schema_ids.iter().for_each(|x| log!("{}", x));
log_info!("Successfully fetched schema IDs");
log_json!({ "schema_ids": schemas.schema_ids })
}),
},
}
Expand Down
34 changes: 19 additions & 15 deletions crates/cli/src/modules/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ pub enum WalletSubcommands {
#[clap(short, long, help=HelpStrings::WalletListDid, required = false)]
did: Option<String>,

/// The key type of the wallet e.g. ed25519, bls12381g2
/// The key type of the wallet
#[clap(short, long, help=HelpStrings::WalletListKeyType, required = false, possible_values=&["ed25519", "bls12381g2"])]
key_type: Option<String>,

/// The did method to query for
#[clap(short, long, help=HelpStrings::WalletListMethod, required = false, possible_values=&["did", "sov"])]
/// The did method to query for either 'key' or 'sov'
#[clap(short, long, help=HelpStrings::WalletListMethod, required = false, possible_values=&["key", "sov"])]
method: Option<String>,

/// Available values : public, posted, wallet_only
Expand All @@ -46,12 +46,12 @@ pub enum WalletSubcommands {
/// Create a local DID
#[clap(about = HelpStrings::WalletCreate)]
CreateLocalDid {
/// The method to be used did or sov
#[clap(long, short, help=HelpStrings::WalletCreateMethod, required = true, default_value="did", possible_values=&["did", "sov"])]
/// The method to be used key or sov
#[clap(long, short, help=HelpStrings::WalletCreateMethod, required = true, possible_values=&["key", "sov"])]
method: String,

/// The key type e.g. ed25519 or bls12381g2
#[clap(long, short, help=HelpStrings::WalletListKeyType, required = true, default_value="ed25519", possible_values=&["ed25519", "bls12381g2"])]
/// The key_type to be used ed25519 or bls12381g2
morrieinmaas marked this conversation as resolved.
Show resolved Hide resolved
#[clap(long, short, help=HelpStrings::WalletListKeyType, required = true, possible_values=&["ed25519", "bls12381g2"])]
key_type: String,
},

Expand Down Expand Up @@ -128,6 +128,7 @@ pub async fn parse_wallet_args(
loader.stop();
log_info!("Found the following DID information for your query: ",);
log!("{}", pretty_stringify_obj(&response));
log_json!(&response);
copy!("{}", pretty_stringify_obj(&response));
})
}
Expand All @@ -140,39 +141,43 @@ pub async fn parse_wallet_args(
};
agent.create_local_did(options).await.map(|response| {
loader.stop();
log_info!("Successfully created local DID: {:?}", response.did);
log_info!("Successfully created local DID: ",);
morrieinmaas marked this conversation as resolved.
Show resolved Hide resolved
copy!("{}", pretty_stringify_obj(&response));
log!("{}", pretty_stringify_obj(response));
log!("{}", pretty_stringify_obj(&response));
log_json!(response)
})
}
WalletSubcommands::RotateKeyPair { did } => {
agent.rotate_keypair(did.clone()).await.map(|response| {
loader.stop();
log_info!("Successfully rotated keypair for did DID {}: ", did);
copy!("{}", pretty_stringify_obj(response));
log!("{}", pretty_stringify_obj(response));
log_json!(response)
})
}
WalletSubcommands::FetchPublicDid {} => agent.fetch_public_did().await.map(|response| {
loader.stop();
log_info!("Wallet public DID: ");
copy!("{}", pretty_stringify_obj(&response));
log!("{}", pretty_stringify_obj(response));
copy!("{}", pretty_stringify_obj(&response.did));
log!("{}", pretty_stringify_obj(&response.did));
log_json!(response)
}),
WalletSubcommands::AssignPublicDid { did } => {
agent.assign_public_did(did.clone()).await.map(|response| {
loader.stop();
log_info!("Successfully assigned public DID: ");
copy!("{}", pretty_stringify_obj(&response));
log!("{}", pretty_stringify_obj(response));
log!("{}", pretty_stringify_obj(&response));
log_json!({"public_did": response.did });
})
}
WalletSubcommands::FetchDidEndpoint { did } => {
agent.fetch_did_endpoint(did.clone()).await.map(|response| {
loader.stop();
log_info!("DID endpoint for DID {}: ", did);
copy!("{}", pretty_stringify_obj(&response));
log!("{}", pretty_stringify_obj(response));
log!("{}", pretty_stringify_obj(&response));
log_json!(response)
})
}
WalletSubcommands::SetDidEndpoint {
Expand All @@ -189,7 +194,6 @@ pub async fn parse_wallet_args(
loader.stop();
log_info!("Set DID endpoint for DID {}: ", did);
log!("{}", pretty_stringify_obj(response));
copy!("{}", pretty_stringify_obj(response));
})
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ pub async fn register() -> Result<()> {
_ => LogLevel::Warn,
}
};
siera_logger::init(level, cli.copy);

siera_logger::init(level, cli.copy, cli.json);

log_trace!("Parsed CLI options and initialized logger");

Expand Down
Loading