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

refactor(api_keys): provide identifier for api key in the expiry reminder email #3888

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/diesel_models/src/api_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ mod diesel_impl {
pub struct ApiKeyExpiryTrackingData {
pub key_id: String,
pub merchant_id: String,
pub api_key_name: String,
pub prefix: String,
pub api_key_expiry: Option<PrimitiveDateTime>,
// Days on which email reminder about api_key expiry has to be sent, prior to it's expiry.
pub expiry_reminder_days: Vec<u8>,
Expand Down
4 changes: 4 additions & 0 deletions crates/router/src/core/api_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ pub async fn add_api_key_expiry_task(
let api_key_expiry_tracker = storage::ApiKeyExpiryTrackingData {
key_id: api_key.key_id.clone(),
merchant_id: api_key.merchant_id.clone(),
api_key_name: api_key.name.clone(),
prefix: api_key.prefix.clone(),
// We need API key expiry too, because we need to decide on the schedule_time in
// execute_workflow() where we won't be having access to the Api key object.
api_key_expiry: api_key.expires_at,
Expand Down Expand Up @@ -369,6 +371,8 @@ pub async fn update_api_key_expiry_task(
let updated_tracking_data = &storage::ApiKeyExpiryTrackingData {
key_id: api_key.key_id.clone(),
merchant_id: api_key.merchant_id.clone(),
api_key_name: api_key.name.clone(),
prefix: api_key.prefix.clone(),
api_key_expiry: api_key.expires_at,
expiry_reminder_days,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,7 @@
cellpadding="0"
cellspacing="0"
>
<tr>
<td
class="spacer-lg"
style="
-premailer-height: 75;
-premailer-width: 100%;
line-height: 30px;
margin: 0 auto;
padding: 0;
"
height="75"
width="100%"
></td>
</tr>

<tr>
<td
class="spacer-lg"
Expand Down Expand Up @@ -96,13 +83,13 @@
line-height: 36px;
margin: 0 auto;
padding: 0;
text-align: center;
text-align: left;
"
align="center"
>
<p style="font-size: 18px">Dear Merchant,</p>
<span style="font-size: 18px">
It has come to our attention that your API key will expire in {expires_in} days. To ensure uninterrupted
It has come to our attention that your API key, <b>{api_key_name}</b> (<code>{prefix}*****</code>) </code> will expire in {expires_in} days. To ensure uninterrupted
access to our platform and continued smooth operation of your services, we kindly request that you take the
necessary actions as soon as possible.
</span>
Expand All @@ -118,39 +105,11 @@
margin: 0 auto;
padding: 0;
"
width="100%"
></td>
</tr>

<tr>
<td
class="spacer-sm"
style="
-premailer-height: 20;
-premailer-width: 100%;
line-height: 10px;
margin: 0 auto;
padding: 0;
"
height="20"
width="100%"
></td>
</tr>

<tr>
<td
class="spacer-lg"
style="
-premailer-height: 75;
-premailer-width: 100%;
line-height: 30px;
margin: 0 auto;
padding: 0;
"
height="75"
width="100%"
></td>
</tr>
<tr>
<td
class="headline"
Expand All @@ -162,7 +121,7 @@
line-height: 36px;
margin: 0 auto;
padding: 0;
text-align: center;
text-align: left;
"
align="center"
>
Expand All @@ -184,20 +143,7 @@
width="100%"
></td>
</tr>
<tr>
<td
class="spacer-lg"
style="
-premailer-height: 75;
-premailer-width: 100%;
line-height: 30px;
margin: 0 auto;
padding: 0;
"
height="75"
width="100%"
></td>
</tr>

</table>
</div>
</body>
14 changes: 13 additions & 1 deletion crates/router/src/services/email/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub enum EmailBody {
},
ApiKeyExpiryReminder {
expires_in: u8,
api_key_name: String,
prefix: String,
},
}

Expand Down Expand Up @@ -128,8 +130,14 @@ Email : {user_email}

(note: This is an auto generated email. Use merchant email for any further communications)",
),
EmailBody::ApiKeyExpiryReminder { expires_in } => format!(
EmailBody::ApiKeyExpiryReminder {
expires_in,
api_key_name,
prefix,
} => format!(
include_str!("assets/api_key_expiry_reminder.html"),
api_key_name = api_key_name,
prefix = prefix,
expires_in = expires_in,
),
}
Expand Down Expand Up @@ -441,6 +449,8 @@ pub struct ApiKeyExpiryReminder {
pub recipient_email: domain::UserEmail,
pub subject: &'static str,
pub expires_in: u8,
pub api_key_name: String,
pub prefix: String,
}

#[async_trait::async_trait]
Expand All @@ -450,6 +460,8 @@ impl EmailData for ApiKeyExpiryReminder {

let body = html::get_html_body(EmailBody::ApiKeyExpiryReminder {
expires_in: self.expires_in,
api_key_name: self.api_key_name.clone(),
prefix: self.prefix.clone(),
});

Ok(EmailContents {
Expand Down
7 changes: 7 additions & 0 deletions crates/router/src/workflows/api_key_expiry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ impl ProcessTrackerWorkflow<AppState> for ApiKeyExpiryWorkflow {

let retry_count = process.retry_count;

let api_key_name = tracking_data.api_key_name.clone();

let prefix = tracking_data.prefix.clone();

let expires_in = tracking_data
.expiry_reminder_days
.get(
Expand All @@ -69,6 +73,9 @@ impl ProcessTrackerWorkflow<AppState> for ApiKeyExpiryWorkflow {
})?,
subject: "API Key Expiry Notice",
expires_in: *expires_in,
api_key_name,
prefix,

};

state
Expand Down
Loading