use super::register::Module;
use crate::agent::agents::Agent;
use async_trait::async_trait;
use clap::ArgMatches;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Connections {
pub results: Vec<Connection>,
}
#[derive(Debug)]
pub struct ConnectionsConfig {
pub alias: Option<String>,
pub connection_id: Option<String>,
pub invitation_key: Option<String>,
pub my_did: Option<String>,
pub their_did: Option<String>,
pub state: Option<String>,
pub their_role: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Connection {
pub invitation_mode: String,
pub rfc23_state: String,
pub invitation_key: String,
pub their_label: Option<String>,
pub accept: String,
pub their_did: Option<String>,
pub created_at: String,
pub their_role: String,
pub updated_at: String,
pub routing_state: String,
pub connection_id: String,
pub my_did: Option<String>,
pub state: String,
pub alias: Option<String>,
}
pub struct ConnectionsModule;
#[async_trait(?Send)]
impl Module<ConnectionsConfig> for ConnectionsModule {
async fn run(agent: &dyn Agent, config: ConnectionsConfig) {
let logger = agent.logger();
match config.connection_id {
Some(id) => {
let connection = agent.get_connection_by_id(id).await;
logger.log_pretty(connection);
}
None => {
let connections = agent.get_connections(config).await.results;
logger.log_pretty(connections);
}
};
}
async fn register<'a>(agent: &dyn Agent, matches: &ArgMatches<'a>) {
if let Some(matches_connections) = matches.subcommand_matches("connections") {
let connection_id = matches_connections
.value_of("connection-id")
.map(|x| x.to_string());
let alias = matches_connections.value_of("alias").map(|x| x.to_string());
let invitation_key = matches_connections
.value_of("invitation-key")
.map(|x| x.to_string());
let my_did = matches_connections
.value_of("my-did")
.map(|x| x.to_string());
let their_did = matches_connections
.value_of("their-did")
.map(|x| x.to_string());
let their_role = matches_connections
.value_of("their_role")
.map(|x| x.to_string());
let state = matches_connections.value_of("state").map(|x| x.to_string());
let config = ConnectionsConfig {
connection_id,
alias,
invitation_key,
my_did,
their_did,
state,
their_role,
};
ConnectionsModule::run(agent, config).await;
}
}
}