-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'miraclx/calimero-identity-dump' into miraclx/use-config…
…-contract
- Loading branch information
Showing
22 changed files
with
401 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use clap::{Parser, ValueEnum}; | ||
use eyre::{bail, Result as EyreResult}; | ||
use reqwest::Client; | ||
|
||
use crate::cli::RootArgs; | ||
use crate::common::RequestType::GET; | ||
use crate::common::{get_response, multiaddr_to_url}; | ||
use crate::config_file::ConfigFile; | ||
|
||
#[derive(Parser, Debug)] | ||
pub struct GetCommand { | ||
#[arg(long, short)] | ||
pub method: GetValues, | ||
|
||
#[arg(long, short)] | ||
pub app_id: String, | ||
} | ||
#[derive(ValueEnum, Debug, Clone)] | ||
pub enum GetValues { | ||
Details, | ||
} | ||
|
||
impl GetCommand { | ||
pub async fn run(self, args: RootArgs) -> EyreResult<()> { | ||
let path = args.home.join(&args.node_name); | ||
|
||
if !ConfigFile::exists(&path) { | ||
bail!("Config file does not exist") | ||
}; | ||
|
||
let Ok(config) = ConfigFile::load(&path) else { | ||
bail!("Failed to load config file") | ||
}; | ||
|
||
let Some(multiaddr) = config.network.server.listen.first() else { | ||
bail!("No address.") | ||
}; | ||
|
||
let client = Client::new(); | ||
|
||
let url = multiaddr_to_url( | ||
multiaddr, | ||
&format!("admin-api/dev/applications/{}", self.app_id), | ||
)?; | ||
|
||
let response = get_response(&client, url, None::<()>, &config.identity, GET).await?; | ||
|
||
if !response.status().is_success() { | ||
bail!("Request failed with status: {}", response.status()) | ||
} | ||
|
||
println!("{}", response.text().await?); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use clap::Parser; | ||
use eyre::{bail, Result as EyreResult}; | ||
use libp2p::Multiaddr; | ||
use reqwest::Client; | ||
|
||
use crate::cli::RootArgs; | ||
use crate::common::{get_response, multiaddr_to_url, RequestType}; | ||
use crate::config_file::ConfigFile; | ||
|
||
#[derive(Debug, Parser)] | ||
pub struct DeleteCommand { | ||
#[clap(long, short)] | ||
pub context_id: String, | ||
} | ||
|
||
impl DeleteCommand { | ||
pub async fn run(self, root_args: RootArgs) -> EyreResult<()> { | ||
let path = root_args.home.join(&root_args.node_name); | ||
if !ConfigFile::exists(&path) { | ||
bail!("Config file does not exist") | ||
} | ||
let Ok(config) = ConfigFile::load(&path) else { | ||
bail!("Failed to load config file"); | ||
}; | ||
let Some(multiaddr) = config.network.server.listen.first() else { | ||
bail!("No address.") | ||
}; | ||
|
||
let client = Client::new(); | ||
|
||
self.delete_context(multiaddr, &client, &config.identity) | ||
.await | ||
} | ||
|
||
async fn delete_context( | ||
&self, | ||
multiaddr: &Multiaddr, | ||
client: &Client, | ||
keypair: &libp2p::identity::Keypair, | ||
) -> EyreResult<()> { | ||
let url = multiaddr_to_url( | ||
multiaddr, | ||
&format!("admin-api/dev/contexts/{}", self.context_id), | ||
)?; | ||
let response = get_response(client, url, None::<()>, keypair, RequestType::DELETE).await?; | ||
|
||
if !response.status().is_success() { | ||
bail!("Request failed with status: {}", response.status()) | ||
} | ||
|
||
let text = response.text().await?; | ||
println!("Context deleted successfully: {}", text); | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.