Skip to content

Commit

Permalink
SKU sdk - update credential matching logic (uplift to 1.58.x) (#20199)
Browse files Browse the repository at this point in the history
Uplift of #20192 (squashed) to release
  • Loading branch information
brave-builds authored Sep 20, 2023
1 parent c42f5e8 commit 12b6d88
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 162 deletions.
32 changes: 18 additions & 14 deletions components/skus/browser/rs/lib/src/sdk/credentials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod fetch;
mod present;

use chrono::Utc;
use tracing::instrument;
use tracing::{error, instrument};

use crate::errors::{InternalError, SkusError};
use crate::models::*;
Expand Down Expand Up @@ -49,9 +49,10 @@ where
if let Some(expires_at) = expires_at {
// attempt to refresh credentials if we're within 5 days of expiry
if Utc::now().naive_utc() > (expires_at - chrono::Duration::days(5)) {
error!("Within 5 days of expiry; refreshing order credentials.");
let refreshed = self.refresh_order_credentials(order_id).await;
if refreshed.is_err() {
continue;
error!("Error refreshing order credentials.");
}
}
}
Expand All @@ -70,6 +71,8 @@ where
active,
}));
}

error!("No matches found for credential summary.");
}
CredentialType::SingleUse => {
let wrapped_creds = self.client.get_single_use_item_creds(&item.id).await?;
Expand Down Expand Up @@ -101,23 +104,24 @@ where
if let Some(expires_at) = expires_at {
// attempt to refresh credentials if we're within 5 days of expiry
if Utc::now().naive_utc() > (expires_at - chrono::Duration::days(5)) {
error!("Within 5 days of expiry; refreshing order credentials.");
let refreshed = self.refresh_order_credentials(order_id).await;
if refreshed.is_err() {
continue;
error!("Error refreshing order credentials.");
}
}
}
let active = matches!(
self.matching_time_limited_credential(&item.id).await,
Ok(Some(_))
);

return Ok(Some(CredentialSummary {
order,
remaining_credential_count: 1,
expires_at,
active,
}));

if let Ok(Some(_)) = self.matching_time_limited_credential(&item.id).await {
return Ok(Some(CredentialSummary {
order,
remaining_credential_count: 1,
expires_at,
active: true,
}));
}

error!("No matches found for credential summary.");
}
};
} // for
Expand Down
Loading

0 comments on commit 12b6d88

Please sign in to comment.