-
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.
feat: implement context invite meroctl command, cleanup admin primitives
- Loading branch information
Showing
20 changed files
with
389 additions
and
197 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
use std::borrow::Cow; | ||
use std::collections::HashSet; | ||
use std::io::Error as IoError; | ||
use std::str::FromStr; | ||
|
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,60 @@ | ||
use calimero_primitives::context::ContextId; | ||
use calimero_primitives::identity::PublicKey; | ||
use calimero_server_primitives::admin::{InviteToContextRequest, InviteToContextResponse}; | ||
use clap::Parser; | ||
use eyre::Result as EyreResult; | ||
use reqwest::Client; | ||
|
||
use crate::cli::Environment; | ||
use crate::common::{do_request, fetch_multiaddr, load_config, multiaddr_to_url, RequestType}; | ||
use crate::output::Report; | ||
|
||
#[derive(Debug, Parser)] | ||
#[command(about = "Create invitation to a context for a invitee")] | ||
pub struct InviteCommand { | ||
#[clap( | ||
value_name = "CONTEXT_ID", | ||
help = "The id of the context for which invitation is created" | ||
)] | ||
pub context_id: ContextId, | ||
|
||
#[clap(value_name = "INVITER_ID", help = "The public key of the inviter")] | ||
pub inviter_id: PublicKey, | ||
|
||
#[clap(value_name = "INVITEE_ID", help = "The public key of the invitee")] | ||
pub invitee_id: PublicKey, | ||
} | ||
|
||
impl Report for InviteToContextResponse { | ||
fn report(&self) { | ||
match self.data { | ||
Some(ref payload) => { | ||
println!("{:?}", payload) | ||
} | ||
None => println!("No invitation payload"), | ||
} | ||
} | ||
} | ||
|
||
impl InviteCommand { | ||
pub async fn run(self, environment: &Environment) -> EyreResult<()> { | ||
let config = load_config(&environment.args.home, &environment.args.node_name)?; | ||
|
||
let response: InviteToContextResponse = do_request( | ||
&Client::new(), | ||
multiaddr_to_url(fetch_multiaddr(&config)?, "admin-api/dev/contexts/invite")?, | ||
Some(InviteToContextRequest { | ||
context_id: self.context_id, | ||
inviter_id: self.inviter_id, | ||
invitee_id: self.invitee_id, | ||
}), | ||
&config.identity, | ||
RequestType::Post, | ||
) | ||
.await?; | ||
|
||
environment.output.write(&response); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use clap::{Parser, Subcommand}; | ||
use const_format::concatcp; | ||
use eyre::Result as EyreResult; | ||
|
||
use crate::cli::identity::generate::GenerateCommand; | ||
use crate::cli::Environment; | ||
|
||
mod generate; | ||
|
||
pub const EXAMPLES: &str = r" | ||
# | ||
$ meroctl -- --node-name node1 identity generate | ||
"; | ||
|
||
#[derive(Debug, Parser)] | ||
#[command(about = "Command for managing applications")] | ||
#[command(after_help = concatcp!( | ||
"Examples:", | ||
EXAMPLES | ||
))] | ||
pub struct IdentityCommand { | ||
#[command(subcommand)] | ||
pub subcommand: IdentitySubCommands, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
pub enum IdentitySubCommands { | ||
Generate(GenerateCommand), | ||
} | ||
|
||
impl IdentityCommand { | ||
pub async fn run(self, environment: &Environment) -> EyreResult<()> { | ||
match self.subcommand { | ||
IdentitySubCommands::Generate(generate) => generate.run(environment).await, | ||
} | ||
} | ||
} |
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,40 @@ | ||
use calimero_server_primitives::admin::GenerateContextIdentityResponse; | ||
use clap::Parser; | ||
use eyre::Result as EyreResult; | ||
use reqwest::Client; | ||
|
||
use crate::cli::Environment; | ||
use crate::common::{do_request, fetch_multiaddr, load_config, multiaddr_to_url, RequestType}; | ||
use crate::output::Report; | ||
|
||
#[derive(Debug, Parser)] | ||
#[command(about = "Generate public/private key pair used for context identity")] | ||
pub struct GenerateCommand {} | ||
|
||
impl Report for GenerateContextIdentityResponse { | ||
fn report(&self) { | ||
println!("public_key: {}", self.data.public_key); | ||
println!("private_key: {}", self.data.private_key); | ||
} | ||
} | ||
|
||
impl GenerateCommand { | ||
pub async fn run(self, environment: &Environment) -> EyreResult<()> { | ||
let config = load_config(&environment.args.home, &environment.args.node_name)?; | ||
|
||
let url = multiaddr_to_url(fetch_multiaddr(&config)?, "admin-api/dev/identity/context")?; | ||
|
||
let response: GenerateContextIdentityResponse = do_request( | ||
&Client::new(), | ||
url, | ||
None::<()>, | ||
&config.identity, | ||
RequestType::Post, | ||
) | ||
.await?; | ||
|
||
environment.output.write(&response); | ||
|
||
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
Oops, something went wrong.