Skip to content

Commit

Permalink
feat(rust): add a value parser for change histories
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathy-bajo authored and etorreborre committed Aug 19, 2024
1 parent e5bdaa5 commit 9a39c2c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
7 changes: 4 additions & 3 deletions implementations/rust/ockam/ockam_api/src/cli_state/trust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::nodes::service::{
};
use crate::nodes::NodeManager;
use crate::{multiaddr_to_transport_route, ApiError, CliState};
use ockam::identity::models::ChangeHistory;
use ockam::identity::{IdentitiesVerification, RemoteCredentialRetrieverInfo};
use ockam_core::errcode::{Kind, Origin};
use ockam_core::{Error, Result};
Expand Down Expand Up @@ -178,11 +179,11 @@ impl CliState {
/// 1. Either we explicitly know the Authority identity that we trust, and optionally route to its node to request
/// a new credential
/// 2. Or we know the project name (or have default one) that contains identity and route to the Authority node
#[instrument(skip_all, fields(project_name = project_name.clone(), authority_identity = authority_identity.clone(), authority_route = authority_route.clone().map_or("n/a".to_string(), |r| r.to_string())))]
#[instrument(skip_all, fields(project_name = project_name.clone(), authority_identity = authority_identity.as_ref().map(|a| a.to_string()).unwrap_or("n/a".to_string()), authority_route = authority_route.clone().map_or("n/a".to_string(), |r| r.to_string())))]
pub async fn retrieve_trust_options(
&self,
project_name: &Option<String>,
authority_identity: &Option<String>,
authority_identity: &Option<ChangeHistory>,
authority_route: &Option<MultiAddr>,
credential_scope: &Option<String>,
) -> Result<NodeManagerTrustOptions> {
Expand All @@ -206,7 +207,7 @@ impl CliState {
if let Some(authority_identity) = authority_identity {
return self
.retrieve_trust_options_explicit_project_authority(
authority_identity,
&authority_identity.export_as_string()?,
authority_route,
credential_scope,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::time::Duration;
use futures::executor;
use miette::IntoDiagnostic;

use ockam::identity::models::ChangeHistory;
use ockam::identity::{Identifier, SecureChannels};
use ockam::tcp::{TcpListenerOptions, TcpTransport};
use ockam::{Context, Result};
Expand Down Expand Up @@ -126,7 +127,7 @@ impl InMemoryNode {
identity_name: &str,
http_server_port: Option<u16>,
project_name: Option<String>,
authority_identity: Option<String>,
authority_identity: Option<ChangeHistory>,
authority_route: Option<MultiAddr>,
) -> miette::Result<InMemoryNode> {
let defaults = NodeManagerDefaults::default();
Expand Down
11 changes: 7 additions & 4 deletions implementations/rust/ockam/ockam_command/src/authority/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use tokio_retry::strategy::FixedInterval;
use tokio_retry::Retry;
use tracing::{debug, error, info};

use ockam::identity::models::ChangeHistory;
use ockam::identity::utils::now;
use ockam::identity::{Identifier, Identity, TimestampInSeconds, Vault};
use ockam::Context;
Expand Down Expand Up @@ -116,8 +117,8 @@ pub struct CreateCommand {

/// Full, hex-encoded Identity (change history) of the account authority to trust
/// for account and project administrator credentials.
#[arg(long, value_name = "ACCOUNT_AUTHORITY_CHANGE_HISTORY", default_value = None)]
account_authority: Option<String>,
#[arg(long, value_name = "ACCOUNT_AUTHORITY_CHANGE_HISTORY", default_value = None, value_parser = ChangeHistory::import_from_string)]
account_authority: Option<ChangeHistory>,

/// Enforce distinction between admins and enrollers
#[arg(long, value_name = "ENFORCE_ADMIN_CHECKS", default_value_t = false)]
Expand Down Expand Up @@ -222,7 +223,7 @@ impl CreateCommand {
}
if let Some(acc_auth_identity) = &self.account_authority {
args.push("--account-authority".to_string());
args.push(acc_auth_identity.clone());
args.push(acc_auth_identity.export_as_string().into_diagnostic()?);
}
if self.enforce_admin_checks {
args.push("--enforce-admin-checks".to_string());
Expand Down Expand Up @@ -332,7 +333,9 @@ impl CreateCommand {
Some(account_authority_change_history) => Some(
Identity::import_from_string(
None,
account_authority_change_history.as_str(),
&account_authority_change_history
.export_as_string()
.into_diagnostic()?,
Vault::create_verifying_vault(),
)
.await
Expand Down
2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam_command/src/node/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub async fn spawn_node(opts: &CommandGlobalOpts, cmd: CreateCommand) -> miette:

if let Some(authority_identity) = authority_identity {
args.push("--authority-identity".to_string());
args.push(authority_identity);
args.push(authority_identity.export_as_string().into_diagnostic()?);
}

if let Some(authority_route) = authority_route {
Expand Down
5 changes: 3 additions & 2 deletions implementations/rust/ockam/ockam_command/src/shared_args.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::util::parsers::duration_parser;
use clap::Args;
use ockam::identity::models::ChangeHistory;
use ockam_core::env::get_env;
use ockam_multiaddr::MultiAddr;
use std::time::Duration;
Expand All @@ -18,8 +19,8 @@ pub struct TrustOpts {
pub project_name: Option<String>,

/// Hex encoded Identity
#[arg(long, value_name = "IDENTITY")]
pub authority_identity: Option<String>,
#[arg(long, value_name = "IDENTITY", value_parser = ChangeHistory::import_from_string)]
pub authority_identity: Option<ChangeHistory>,

/// Address to the Authority node
#[arg(long)]
Expand Down

0 comments on commit 9a39c2c

Please sign in to comment.