Skip to content

Commit

Permalink
Merge branch 'master' into feature/csharp_-wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
bbujak authored Sep 21, 2023
2 parents 76039dd + 25d857e commit 1717a56
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
2 changes: 2 additions & 0 deletions crates/bitwarden/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
18 changes: 11 additions & 7 deletions crates/bitwarden/src/secrets_manager/projects/project_response.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bitwarden_api_api::models::ProjectResponseModel;
use chrono::{DateTime, Utc};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
Expand All @@ -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<Utc>,
pub revision_date: DateTime<Utc>,
}

impl ProjectResponse {
Expand All @@ -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()?,
})
}
}
17 changes: 11 additions & 6 deletions crates/bitwarden/src/secrets_manager/secrets/secret_response.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Uuid>,
Expand All @@ -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<Utc>,
pub revision_date: DateTime<Utc>,
}

impl SecretResponse {
Expand Down Expand Up @@ -73,16 +73,21 @@ 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,
key,
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()?,
})
}
}
Expand Down
9 changes: 3 additions & 6 deletions crates/bws/src/render.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -105,11 +105,8 @@ impl<T: TableSerialize<N>, const N: usize> TableSerialize<N> for Vec<T> {
}
}

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<Utc>) -> String {
date.format("%Y-%m-%d %H:%M:%S").to_string()
}

impl TableSerialize<3> for ProjectResponse {
Expand Down

0 comments on commit 1717a56

Please sign in to comment.