Skip to content

Commit

Permalink
Change to parse
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Sep 19, 2023
1 parent 34dc51c commit b053be1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::{
client::encryption_settings::EncryptionSettings,
crypto::{Decryptable, EncString},
error::{Error, Result},
util::parse_date,
};

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
Expand Down Expand Up @@ -39,8 +38,14 @@ impl ProjectResponse {
organization_id,
name,

creation_date: parse_date(&response.creation_date.ok_or(Error::MissingFields)?)?,
revision_date: parse_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()?,
})
}
}
11 changes: 8 additions & 3 deletions crates/bitwarden/src/secrets_manager/secrets/secret_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::{
client::encryption_settings::EncryptionSettings,
crypto::{Decryptable, EncString},
error::{Error, Result},
util::parse_date,
};

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
Expand Down Expand Up @@ -81,8 +80,14 @@ impl SecretResponse {
value,
note,

creation_date: parse_date(&response.creation_date.ok_or(Error::MissingFields)?)?,
revision_date: parse_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
6 changes: 0 additions & 6 deletions crates/bitwarden/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use base64::{
engine::{DecodePaddingMode, GeneralPurpose, GeneralPurposeConfig},
Engine,
};
use chrono::{DateTime, Utc};

use crate::error::Result;

Expand Down Expand Up @@ -51,11 +50,6 @@ pub fn decode_token(token: &str) -> Result<JWTToken> {
Ok(serde_json::from_slice(&decoded)?)
}

/// Parse a date in RFC3339 format
pub(crate) fn parse_date(date: &str) -> Result<DateTime<Utc>> {
Ok(DateTime::parse_from_rfc3339(date)?.with_timezone(&Utc))
}

#[cfg(test)]
mod tests {
#[test]
Expand Down

0 comments on commit b053be1

Please sign in to comment.