Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instrument portal messages #8854

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ockam_core::compat::vec::Vec;
use ockam_core::Result;
use ockam_identity::{Identifier, IdentitiesAttributes};
use strum::IntoEnumIterator;
use tracing::{debug, instrument};
use tracing::{debug, instrument, Level};

#[derive(Clone)]
pub struct Policies {
Expand All @@ -28,7 +28,7 @@ impl Policies {
}
}

#[instrument(skip_all, fields(resource = %resource, action = %action, env = %env, authority = ?authority))]
#[instrument(skip_all, fields(resource = %resource, action = %action, env = %env, authority = ?authority), level = Level::TRACE)]
pub fn make_policy_access_control(
&self,
identities_attributes: Arc<IdentitiesAttributes>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ockam::identity::utils::AttributesBuilder;
use ockam::identity::{Attributes, Credentials, Identifier, IdentitiesAttributes};
use ockam_core::compat::sync::Arc;
use ockam_core::Result;
use tracing::Level;

/// Legacy value, should be removed when all clients are updated to the latest version
pub const TRUST_CONTEXT_ID: &[u8] = b"trust_context_id";
Expand All @@ -32,7 +33,7 @@ pub struct CredentialIssuer {
impl CredentialIssuer {
/// Create a new credentials issuer
#[allow(clippy::too_many_arguments)]
#[instrument(skip_all, fields(issuer = %issuer, project_identifier = project_identifier.clone(), credential_ttl = credential_ttl.map_or("n/a".to_string(), |d| d.as_secs().to_string())))]
#[instrument(skip_all, fields(issuer = %issuer, project_identifier = project_identifier.clone(), credential_ttl = credential_ttl.map_or("n/a".to_string(), |d| d.as_secs().to_string())), level = Level::TRACE)]
pub fn new(
members: Arc<dyn AuthorityMembersRepository>,
identities_attributes: Arc<IdentitiesAttributes>,
Expand Down Expand Up @@ -66,7 +67,7 @@ impl CredentialIssuer {
}
}

#[instrument(skip_all, fields(subject = %subject))]
#[instrument(skip_all, fields(subject = %subject), level = Level::TRACE)]
pub async fn issue_credential(
&self,
subject: &Identifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use either::Either;
use std::collections::{BTreeMap, HashMap};
use tracing::Level;

use ockam::identity::utils::now;
use ockam::identity::Identifier;
Expand Down Expand Up @@ -76,7 +77,7 @@ impl DirectAuthenticator {
}
}

#[instrument(skip_all, fields(enroller = %enroller, identifier = %identifier))]
#[instrument(skip_all, fields(enroller = %enroller, identifier = %identifier), level = Level::TRACE)]
pub async fn add_member(
&self,
enroller: &Identifier,
Expand Down Expand Up @@ -141,7 +142,7 @@ impl DirectAuthenticator {
Ok(Either::Left(()))
}

#[instrument(skip_all, fields(enroller = %enroller))]
#[instrument(skip_all, fields(enroller = %enroller), level = Level::TRACE)]
pub async fn show_member(
&self,
enroller: &Identifier,
Expand Down Expand Up @@ -183,7 +184,7 @@ impl DirectAuthenticator {
}
}

#[instrument(skip_all, fields(enroller = %enroller))]
#[instrument(skip_all, fields(enroller = %enroller), level = Level::TRACE)]
pub async fn list_members(
&self,
enroller: &Identifier,
Expand Down Expand Up @@ -220,7 +221,7 @@ impl DirectAuthenticator {
Ok(Either::Left(res))
}

#[instrument(skip_all, fields(enroller = %enroller))]
#[instrument(skip_all, fields(enroller = %enroller), level = Level::TRACE)]
pub async fn delete_all_members(
&self,
enroller: &Identifier,
Expand All @@ -238,7 +239,7 @@ impl DirectAuthenticator {
}
}

#[instrument(skip_all, fields(enroller = %enroller, identifier = %identifier))]
#[instrument(skip_all, fields(enroller = %enroller, identifier = %identifier), level = Level::TRACE)]
pub async fn delete_member(
&self,
enroller: &Identifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use either::Either;
use tracing::Level;

use ockam::identity::utils::now;
use ockam::identity::Identifier;
use ockam_core::compat::sync::Arc;
Expand Down Expand Up @@ -33,7 +35,7 @@ impl EnrollmentTokenAcceptor {
}
}

#[instrument(skip_all, fields(from = %from))]
#[instrument(skip_all, fields(from = %from), level = Level::TRACE)]
pub async fn accept_token(
&mut self,
otc: OneTimeCode,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use miette::IntoDiagnostic;
use tracing::Level;

use ockam_core::api::Request;
use ockam_core::async_trait;
Expand All @@ -15,7 +16,7 @@ pub trait TokenAcceptor {

#[async_trait]
impl TokenAcceptor for AuthorityNodeClient {
#[instrument(skip_all)]
#[instrument(skip_all, level = Level::TRACE)]
async fn present_token(&self, ctx: &Context, token: OneTimeCode) -> miette::Result<()> {
let req = Request::post("/").body(token);
self.get_secure_client()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use either::Either;
use rand::distributions::Alphanumeric;
use rand::Rng;
use std::collections::BTreeMap;
use tracing::Level;

use ockam::identity::utils::now;
use ockam::identity::{Identifier, IdentitiesAttributes};
Expand Down Expand Up @@ -50,7 +51,7 @@ impl EnrollmentTokenIssuer {
}
}

#[instrument(skip_all, fields(enroller = %enroller, token_duration = token_duration.map_or("n/a".to_string(), |d| d.as_secs().to_string()), ttl_count = ttl_count.map_or("n/a".to_string(), |t| t.to_string())))]
#[instrument(skip_all, fields(enroller = %enroller, token_duration = token_duration.map_or("n/a".to_string(), |d| d.as_secs().to_string()), ttl_count = ttl_count.map_or("n/a".to_string(), |t| t.to_string())), level = Level::TRACE)]
pub async fn issue_token(
&self,
enroller: &Identifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
use std::str::FromStr;
use time::OffsetDateTime;
use tracing::Level;

/// The following CliState methods help keeping track of
/// the enrollment status of identities.
impl CliState {
#[instrument(skip_all, fields(name = name.clone()))]
#[instrument(skip_all, fields(name = name.clone()), level = Level::TRACE)]
pub async fn is_identity_enrolled(&self, name: &Option<String>) -> Result<bool> {
let repository = self.enrollment_repository();

Expand All @@ -28,15 +29,15 @@ impl CliState {
}
}

#[instrument(skip_all)]
#[instrument(skip_all, level = Level::TRACE)]
pub async fn is_default_identity_enrolled(&self) -> Result<bool> {
Ok(self
.enrollment_repository()
.is_default_identity_enrolled()
.await?)
}

#[instrument(skip_all)]
#[instrument(skip_all, level = Level::TRACE)]
pub async fn identity_should_enroll(&self, name: &Option<String>, force: bool) -> Result<bool> {
if force {
return Ok(true);
Expand All @@ -51,7 +52,7 @@ impl CliState {
Ok(!self.is_identity_enrolled(name).await?)
}

#[instrument(skip_all, fields(identifier = %identifier))]
#[instrument(skip_all, fields(identifier = %identifier), level = Level::TRACE)]
pub async fn set_identifier_as_enrolled(
&self,
identifier: &Identifier,
Expand All @@ -67,7 +68,7 @@ impl CliState {
///
/// - all the currently enrolled entities
/// - all the known identities and their corresponding enrollment state
#[instrument(skip_all, fields(filter = %filter))]
#[instrument(skip_all, fields(filter = %filter), level = Level::TRACE)]
pub async fn get_identity_enrollments(
&self,
filter: EnrollmentFilter,
Expand All @@ -93,7 +94,7 @@ impl CliState {
/// Return true if the user is enrolled.
/// At the moment this check only verifies that there is a default project.
/// This project should be the project that is created at the end of the enrollment procedure
#[instrument(skip_all)]
#[instrument(skip_all, level = Level::TRACE)]
pub async fn is_enrolled(&self) -> miette::Result<bool> {
if !self.is_default_identity_enrolled().await? {
return Ok(false);
Expand Down
39 changes: 20 additions & 19 deletions implementations/rust/ockam/ockam_api/src/cli_state/identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ockam::identity::{Identifier, Identity};
use ockam_core::errcode::{Kind, Origin};
use ockam_core::Error;
use ockam_vault::{HandleToSecret, SigningSecretKeyHandle};
use tracing::Level;

use crate::cli_state::{random_name, CliState, Result};
use crate::colors::color_primary;
Expand All @@ -28,7 +29,7 @@ use crate::{fmt_log, fmt_ok};
impl CliState {
/// Create an identity associated with a name and a specific vault name
/// If there is already an identity with that name, return its identifier
#[instrument(skip_all, fields(name = %name, vault_name = %vault_name))]
#[instrument(skip_all, fields(name = %name, vault_name = %vault_name), level = Level::TRACE)]
pub async fn create_identity_with_name_and_vault(
&self,
name: &str,
Expand Down Expand Up @@ -64,7 +65,7 @@ impl CliState {

/// Create an identity associated with a name, using the default vault
/// If there is already an identity with that name, return its identifier
#[instrument(skip_all, fields(name = %name))]
#[instrument(skip_all, fields(name = %name), level = Level::TRACE)]
pub async fn create_identity_with_name(&self, name: &str) -> Result<NamedIdentity> {
let vault = self.get_or_create_default_named_vault().await?;
self.create_identity_with_name_and_vault(name, &vault.name())
Expand All @@ -74,7 +75,7 @@ impl CliState {
/// Create an identity with specific key id.
/// This method is used when the vault is a KMS vault and we just need to store a key id
/// for the identity key existing in the KMS
#[instrument(skip_all, fields(name = %name, vault_name = %vault_name, key_id = %key_id))]
#[instrument(skip_all, fields(name = %name, vault_name = %vault_name, key_id = %key_id), level = Level::TRACE)]
pub async fn create_identity_with_key_id(
&self,
name: &str,
Expand Down Expand Up @@ -123,13 +124,13 @@ impl CliState {
///
impl CliState {
/// Return all named identities
#[instrument(skip_all)]
#[instrument(skip_all, level = Level::TRACE)]
pub async fn get_named_identities(&self) -> Result<Vec<NamedIdentity>> {
Ok(self.identities_repository().get_named_identities().await?)
}

/// Return a named identity given its name
#[instrument(skip_all, fields(name = %name))]
#[instrument(skip_all, fields(name = %name), level = Level::TRACE)]
pub async fn get_named_identity(&self, name: &str) -> Result<NamedIdentity> {
let repository = self.identities_repository();
match repository.get_named_identity(name).await? {
Expand All @@ -151,7 +152,7 @@ impl CliState {
}

/// Return a named identity given its name or the default named identity
#[instrument(skip_all, fields(name = name.clone()))]
#[instrument(skip_all, fields(name = name.clone()), level = Level::TRACE)]
pub async fn get_named_identity_or_default(
&self,
name: &Option<String>,
Expand All @@ -171,7 +172,7 @@ impl CliState {

/// Return the identifier for identity given an optional name.
/// If that name is None, then we return the identifier of the default identity
#[instrument(skip_all, fields(name = name.clone()))]
#[instrument(skip_all, fields(name = name.clone()), level = Level::TRACE)]
pub async fn get_identifier_by_optional_name(
&self,
name: &Option<String>,
Expand All @@ -190,7 +191,7 @@ impl CliState {

/// Return a full identity from its name
/// Use the default identity if no name is given
#[instrument(skip_all, fields(name = name.clone()))]
#[instrument(skip_all, fields(name = name.clone()), level = Level::TRACE)]
pub async fn get_identity_by_optional_name(&self, name: &Option<String>) -> Result<Identity> {
let named_identity = match name {
Some(name) => {
Expand Down Expand Up @@ -222,7 +223,7 @@ impl CliState {
}

/// Return the identity with the given identifier
#[instrument(skip_all, fields(identifier = %identifier))]
#[instrument(skip_all, fields(identifier = %identifier), level = Level::TRACE)]
pub async fn get_identity(&self, identifier: &Identifier) -> Result<Identity> {
match self
.change_history_repository()
Expand All @@ -242,14 +243,14 @@ impl CliState {

/// Return the name of the default identity.
/// This function creates the default identity if it does not exist!
#[instrument(skip_all)]
#[instrument(skip_all, level = Level::TRACE)]
pub async fn get_default_identity_name(&self) -> Result<String> {
Ok(self.get_or_create_default_named_identity().await?.name())
}

/// Return the default named identity
/// This function creates the default identity if it does not exist!
#[instrument(skip_all)]
#[instrument(skip_all, level = Level::TRACE)]
pub async fn get_or_create_default_named_identity(&self) -> Result<NamedIdentity> {
match self
.identities_repository()
Expand All @@ -271,7 +272,7 @@ impl CliState {
/// Return:
/// - the given name if defined
/// - or the name of the default identity (which is created if it does not already exist!)
#[instrument(skip_all, fields(name = name.clone()))]
#[instrument(skip_all, fields(name = name.clone()), level = Level::TRACE)]
pub async fn get_identity_name_or_default(&self, name: &Option<String>) -> Result<String> {
match name {
Some(name) => Ok(name.clone()),
Expand All @@ -280,7 +281,7 @@ impl CliState {
}

/// Return the named identity with the given identifier
#[instrument(skip_all, fields(identifier = %identifier))]
#[instrument(skip_all, fields(identifier = %identifier), level = Level::TRACE)]
pub async fn get_named_identity_by_identifier(
&self,
identifier: &Identifier,
Expand All @@ -300,7 +301,7 @@ impl CliState {
}

/// Return true if there is an identity with that name and it is the default one
#[instrument(skip_all, fields(name = %name))]
#[instrument(skip_all, fields(name = %name), level = Level::TRACE)]
pub async fn is_default_identity_by_name(&self, name: &str) -> Result<bool> {
Ok(self
.identities_repository()
Expand All @@ -315,7 +316,7 @@ impl CliState {
impl CliState {
/// Set a named identity as the default
/// Return an error if that identity does not exist
#[instrument(skip_all, fields(name = %name))]
#[instrument(skip_all, fields(name = %name), level = Level::TRACE)]
pub async fn set_as_default_identity(&self, name: &str) -> Result<()> {
Ok(self.identities_repository().set_as_default(name).await?)
}
Expand All @@ -326,7 +327,7 @@ impl CliState {
/// - then remove the the name association to the identity
/// - and remove the identity change history
///
#[instrument(skip_all, fields(name = %name))]
#[instrument(skip_all, fields(name = %name), level = Level::TRACE)]
pub async fn delete_identity_by_name(&self, name: &str) -> Result<()> {
let nodes = self.get_nodes_by_identity_name(name).await?;
if nodes.is_empty() {
Expand All @@ -350,7 +351,7 @@ impl CliState {
}

/// Update the name associated to an identifier
#[instrument(skip_all, fields(identifier = %identifier, name = %name))]
#[instrument(skip_all, fields(identifier = %identifier, name = %name), level = Level::TRACE)]
pub async fn update_named_identity_name(
&self,
identifier: &Identifier,
Expand All @@ -367,7 +368,7 @@ impl CliState {
impl CliState {
/// Once a identity has been created, store it.
/// If there is no previous default identity we set it as the default identity
#[instrument(skip_all, fields(name = %name, identifier = %identifier, vault_name = %vault_name))]
#[instrument(skip_all, fields(name = %name, identifier = %identifier, vault_name = %vault_name), level = Level::TRACE)]
pub async fn store_named_identity(
&self,
identifier: &Identifier,
Expand All @@ -391,7 +392,7 @@ impl CliState {
}

/// Return the change history of a persisted identity
#[instrument(skip_all, fields(identifier = %identifier))]
#[instrument(skip_all, fields(identifier = %identifier), level = Level::TRACE)]
async fn get_change_history(&self, identifier: &Identifier) -> Result<ChangeHistory> {
match self
.change_history_repository()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn default_attributes<'a>() -> HashMap<&'a Key, String> {
/// - The next 25 characters identify the host
/// - The last 6 characters are the 'now' date as YYMMDD
///
pub(crate) fn make_host_trace_id(now: DateTime<Utc>) -> TraceId {
pub fn make_host_trace_id(now: DateTime<Utc>) -> TraceId {
let machine = adjust(make_host(), 25, '1');
// date as a 6 characters string
let now = now_as_string(now);
Expand All @@ -54,7 +54,7 @@ pub(crate) fn make_host_trace_id(now: DateTime<Utc>) -> TraceId {
/// This allows to bucket all the spans in the same trace, even if the spans come from different machines which
/// can start their own project journey trace independently.
///
pub(crate) fn make_project_trace_id(project_id: &str, now: DateTime<Utc>) -> TraceId {
pub fn make_project_trace_id(project_id: &str, now: DateTime<Utc>) -> TraceId {
// take the whole project without '-' as the base for the trace id
// make sure that there exactly 25 characters
let project_id_trace_id = adjust(project_id.to_string().replace('-', ""), 25, '1');
Expand Down
Loading
Loading