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

Add self signed certificate for smtp transport option #40

Merged

Conversation

rupal-bq
Copy link
Contributor

@rupal-bq rupal-bq commented Apr 6, 2023

Description

  • Added --selfsignedcerts option to allow use of self signed certificate for smtp transport

Issues Resolved

#31

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

rupal-bq added 3 commits April 6, 2023 23:24
Signed-off-by: Rupal Mahajan <[email protected]>
Signed-off-by: Rupal Mahajan <[email protected]>
@rupal-bq rupal-bq marked this pull request as ready for review April 7, 2023 16:19
@rupal-bq rupal-bq requested a review from a team as a code owner April 7, 2023 16:19
@rupal-bq rupal-bq merged commit 5268263 into opensearch-project:main Apr 7, 2023
Copy link

@pjfitzgibbons pjfitzgibbons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes for you. Maybe consider these changes for next PR on this utility.

@@ -94,6 +97,8 @@ async function getEventArguments(event) {
event['note'] = DEFAULT_EMAIL_NOTE;
if (event.multitenancy === undefined)
event['multitenancy'] = DEFAULT_MULTI_TENANCY;
if (event.selfsignedcerts === undefined)
event['selfsignedcerts'] = DEFAULT_SELF_SIGNED_CERTIFICATES;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try this merge strategy :

const defaults = {
  auth: DEFAULT_AUTH,
  tenant: DEFAULT_TENANT,
  ... (etc)
}

Object.assign(defaults, ...event)

I think would both clarify the defaults, and make the fallback assignments a one-liner.

@@ -20,7 +20,7 @@ try {
// Do not set AWS_SDK_LOAD_CONFIG if aws config file is missing.
}

module.exports = async function sendEmail(filename, url, sender, recipient, transport, smtphost, smtpport, smtpsecure, smtpusername, smtppassword, subject, note, emailbody) {
module.exports = async function sendEmail(filename, url, sender, recipient, transport, smtphost, smtpport, smtpsecure, smtpusername, smtppassword, subject, note, emailbody, selfsignedcerts) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might start to make sense to turn this into an object-reference, with an interface. Naming might be hard, though I could make more sense and less brain-power out of arguments named {emailContent, smtpConfig} with associated interfaces.

This would also mean that further config changes (new options) do not cause change on this method (or at least this method signature

@@ -20,7 +20,7 @@ try {
// Do not set AWS_SDK_LOAD_CONFIG if aws config file is missing.
}

module.exports = async function sendEmail(filename, url, sender, recipient, transport, smtphost, smtpport, smtpsecure, smtpusername, smtppassword, subject, note, emailbody) {
module.exports = async function sendEmail(filename, url, sender, recipient, transport, smtphost, smtpport, smtpsecure, smtpusername, smtppassword, subject, note, emailbody, selfsignedcerts) {
if (transport !== undefined && (transport === 'smtp' || ses !== undefined) && sender !== undefined && recipient !== undefined) {
spinner.start('Sending email...');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like making this module to two different things : 1. format/send email. 2. control UI/UX.

I think the only question in splitting this up would be if there is expected some "on-the-fly" UX while the email-sending process is ongoing... In our modern computing environment, there shouldn't be a timing issue... emails never take > 10sec so send.. or else they fail immediately.

success(info);
}
});
transporter.sendMail(mailOptions, function (err, info) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a lot more clear using a try..catch.. .and if necessary a throw on self-detected error (err value is not null?)

@rupal-bq rupal-bq mentioned this pull request Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants