-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: multitenancy create and remove wallet (#184)
Signed-off-by: Berend Sliedrecht <[email protected]> Co-authored-by: Jean-Louis Leysens <[email protected]>
- Loading branch information
1 parent
9cb5c97
commit cc70871
Showing
12 changed files
with
157 additions
and
3 deletions.
There are no files selected for viewing
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,37 @@ | ||
use async_trait::async_trait; | ||
|
||
use crate::error::Result; | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
use serde_json::Value; | ||
|
||
/// Response of the `create` endpoint on the multitenancy module | ||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] | ||
pub struct MultitenancyCreateResponse { | ||
/// Timestamp of when the subwallet was created | ||
pub created_at: String, | ||
/// The mode of the key management (managed, unmanaged) | ||
pub key_management_mode: String, | ||
|
||
/// More wallet information | ||
pub settings: Value, | ||
|
||
/// JWT | ||
pub token: String, | ||
|
||
/// Timestamp of when the last update happened to the wallet | ||
pub updated_at: String, | ||
|
||
/// The wallet id | ||
pub wallet_id: String, | ||
} | ||
|
||
/// Multitenancy module for a generic cloudagent | ||
#[async_trait] | ||
pub trait MultitenancyModule { | ||
/// Create a new subwallet | ||
async fn create(&self) -> Result<MultitenancyCreateResponse>; | ||
|
||
/// Remove a subwallet | ||
async fn remove(&self, wallet_id: String) -> Result<()>; | ||
} |
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 |
---|---|---|
|
@@ -24,3 +24,6 @@ pub mod proof; | |
|
||
/// Module for schemas | ||
pub mod schema; | ||
|
||
/// Module for multitenancy | ||
pub mod multitenancy; |
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,54 @@ | ||
use crate::{ | ||
error::Result, | ||
help_strings::HelpStrings, | ||
utils::loader::{Loader, LoaderVariant}, | ||
}; | ||
use agent::modules::multitenancy::MultitenancyModule; | ||
use clap::{Args, Subcommand}; | ||
|
||
/// Credential Definition options and flags | ||
#[derive(Args)] | ||
#[clap(about = "CRUD functionality with multitenancy wallets")] | ||
pub struct MultitenancyOptions { | ||
/// All the subcommands of the multitenancy cli | ||
#[clap(subcommand)] | ||
pub commands: MultitenancySubcommands, | ||
} | ||
|
||
/// Credential Definition subcommands | ||
#[derive(Subcommand, Debug)] | ||
pub enum MultitenancySubcommands { | ||
/// Create a subwallet | ||
#[clap(about = HelpStrings::MultitenancyCreate)] | ||
Create {}, | ||
|
||
/// Remove a subwallet | ||
#[clap(about = HelpStrings::MultitenancyRemove)] | ||
Remove { | ||
/// List a single credential definition by id | ||
#[clap(long, short, help = HelpStrings::MultitenancyRemoveWalletId)] | ||
wallet_id: String, | ||
}, | ||
} | ||
|
||
/// Subcommand multitenancy parser | ||
pub async fn parse_multitenancy_args( | ||
options: &MultitenancyOptions, | ||
agent: impl MultitenancyModule, | ||
) -> Result<()> { | ||
let loader = Loader::start(LoaderVariant::default()); | ||
|
||
match &options.commands { | ||
MultitenancySubcommands::Create {} => agent.create().await.map(|response| { | ||
loader.stop(); | ||
copy!("{}", response.wallet_id); | ||
log!("{}", response.wallet_id); | ||
}), | ||
MultitenancySubcommands::Remove { wallet_id } => { | ||
agent.remove(wallet_id.to_owned()).await?; | ||
loader.stop(); | ||
log!("Successfully removed wallet with id: {}", wallet_id); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use super::agent::CloudAgentPython; | ||
use agent::modules::multitenancy::MultitenancyModule; | ||
use agent::{error::Result, modules::multitenancy::MultitenancyCreateResponse}; | ||
use async_trait::async_trait; | ||
use serde_json::{json, Value}; | ||
|
||
#[async_trait] | ||
impl MultitenancyModule for CloudAgentPython { | ||
/// TODO: this only returns the wallet id for now | ||
async fn create(&self) -> Result<MultitenancyCreateResponse> { | ||
let url = self | ||
.cloud_agent | ||
.create_url(vec!["multitenancy", "wallet"])?; | ||
|
||
self.cloud_agent | ||
.post::<MultitenancyCreateResponse>(url, None, Some(json!({}))) | ||
.await | ||
} | ||
|
||
async fn remove(&self, wallet_id: String) -> Result<()> { | ||
let url = | ||
self.cloud_agent | ||
.create_url(vec!["multitenancy", "wallet", &wallet_id, "remove"])?; | ||
|
||
self.cloud_agent.post::<Value>(url, None, None).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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,4 @@ services: | |
--admin-insecure-mode \ | ||
--label 'tester_agent' \ | ||
--log-level 'info' ", | ||
] | ||
] |