diff --git a/crates/bitwarden/src/error.rs b/crates/bitwarden/src/error.rs index cd742f810..6a9b0d8aa 100644 --- a/crates/bitwarden/src/error.rs +++ b/crates/bitwarden/src/error.rs @@ -40,6 +40,8 @@ pub enum Error { Io(#[from] std::io::Error), #[error(transparent)] InvalidBase64(#[from] base64::DecodeError), + #[error(transparent)] + Chrono(#[from] chrono::ParseError), #[error("Received error message from server: [{}] {}", .status, .message)] ResponseContent { status: StatusCode, message: String }, diff --git a/crates/bitwarden/src/secrets_manager/projects/project_response.rs b/crates/bitwarden/src/secrets_manager/projects/project_response.rs index 52980c45f..b8c82806b 100644 --- a/crates/bitwarden/src/secrets_manager/projects/project_response.rs +++ b/crates/bitwarden/src/secrets_manager/projects/project_response.rs @@ -1,4 +1,5 @@ use bitwarden_api_api::models::ProjectResponseModel; +use chrono::{DateTime, Utc}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use uuid::Uuid; @@ -12,12 +13,11 @@ use crate::{ #[derive(Serialize, Deserialize, Debug, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct ProjectResponse { - pub object: String, pub id: Uuid, pub organization_id: Uuid, pub name: String, - pub creation_date: String, - pub revision_date: String, + pub creation_date: DateTime, + pub revision_date: DateTime, } impl ProjectResponse { @@ -34,14 +34,18 @@ impl ProjectResponse { .decrypt(enc, &Some(organization_id))?; Ok(ProjectResponse { - object: "project".to_owned(), - id: response.id.ok_or(Error::MissingFields)?, organization_id, name, - creation_date: response.creation_date.ok_or(Error::MissingFields)?, - revision_date: response.revision_date.ok_or(Error::MissingFields)?, + creation_date: response + .creation_date + .ok_or(Error::MissingFields)? + .parse()?, + revision_date: response + .revision_date + .ok_or(Error::MissingFields)? + .parse()?, }) } } diff --git a/crates/bitwarden/src/secrets_manager/secrets/secret_response.rs b/crates/bitwarden/src/secrets_manager/secrets/secret_response.rs index 635d1e3c0..a7fe49200 100644 --- a/crates/bitwarden/src/secrets_manager/secrets/secret_response.rs +++ b/crates/bitwarden/src/secrets_manager/secrets/secret_response.rs @@ -1,6 +1,7 @@ use bitwarden_api_api::models::{ BaseSecretResponseModel, BaseSecretResponseModelListResponseModel, SecretResponseModel, }; +use chrono::{DateTime, Utc}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use uuid::Uuid; @@ -14,7 +15,6 @@ use crate::{ #[derive(Serialize, Deserialize, Debug, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct SecretResponse { - pub object: String, pub id: Uuid, pub organization_id: Uuid, pub project_id: Option, @@ -23,8 +23,8 @@ pub struct SecretResponse { pub value: String, pub note: String, - pub creation_date: String, - pub revision_date: String, + pub creation_date: DateTime, + pub revision_date: DateTime, } impl SecretResponse { @@ -73,7 +73,6 @@ impl SecretResponse { .and_then(|p| p.id); Ok(SecretResponse { - object: "secret".to_owned(), id: response.id.ok_or(Error::MissingFields)?, organization_id: org_id.ok_or(Error::MissingFields)?, project_id: project, @@ -81,8 +80,14 @@ impl SecretResponse { value, note, - creation_date: response.creation_date.ok_or(Error::MissingFields)?, - revision_date: response.revision_date.ok_or(Error::MissingFields)?, + creation_date: response + .creation_date + .ok_or(Error::MissingFields)? + .parse()?, + revision_date: response + .revision_date + .ok_or(Error::MissingFields)? + .parse()?, }) } } diff --git a/crates/bws/src/render.rs b/crates/bws/src/render.rs index 7a7822113..4f2a32e9a 100644 --- a/crates/bws/src/render.rs +++ b/crates/bws/src/render.rs @@ -1,5 +1,5 @@ use bitwarden::secrets_manager::{projects::ProjectResponse, secrets::SecretResponse}; -use chrono::DateTime; +use chrono::{DateTime, Utc}; use clap::ValueEnum; use comfy_table::Table; use serde::Serialize; @@ -105,11 +105,8 @@ impl, const N: usize> TableSerialize for Vec { } } -fn format_date(date: &str) -> String { - DateTime::parse_from_rfc3339(date) - .unwrap() - .format("%Y-%m-%d %H:%M:%S") - .to_string() +fn format_date(date: &DateTime) -> String { + date.format("%Y-%m-%d %H:%M:%S").to_string() } impl TableSerialize<3> for ProjectResponse {