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

Automate reminder mails #3

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

kiriappeee
Copy link
Member

No description provided.

@kiriappeee
Copy link
Member Author

@djfarrelly it's ready-ish to roll out. This is pretty rough. I've sent what keysinfo.json looks like to you separately. Right now I'm filling in the details. 😁

Copy link

@djfarrelly djfarrelly left a comment

Choose a reason for hiding this comment

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

Hey @kiriappeee, overall, this looks great!! Nice work 😄 I decided to add some js-syntax/style comments in this PR since you're starting to pick up some more JS in addition to your heavy Python usage. I don't mean to nit-pick, just provide some js tips 😃

Functionality wise, this looks good, but it would be great to have an example keysinfo.json file in the repo.

index.js Outdated
const { Users: users} = await iam.listUsers({}).promise()
stopChecking = false

Choose a reason for hiding this comment

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

It would be good to use a let stopChecking = false to declare this variable

Choose a reason for hiding this comment

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

On second review, is this variable used anywhere? Can we remove it?

index.js Outdated
const getKeyDetails = async ({
keyNames
}) => {
const keyInfoFileContents = await readFileAsync(join(__dirname, './keys.info'))

Choose a reason for hiding this comment

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

Can we perhaps add a keys.info.example file to this repo and check it in so future devs can reference that?

Choose a reason for hiding this comment

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

Is this file keys.info or keysinfo.json (see .gitignore)? I think if it's a json file the file should have a .json extension 😄

index.js Outdated
) {
console.log(`Found Expired Key: ${UserName} - ${key.AccessKeyId} - ${daysOld} days old`)
expiredKeys.push({
user: UserName,
keyId: key.AccessKeyId,
daysOld,
})
if (daysOld == daysError || (daysOld-daysError)%12== 0) {

Choose a reason for hiding this comment

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

In js world it's always preferable to use === instead of == for equality as == can be true in certain cases triple-equals isn't. You may already know this, but if, not just sharing a js tip as I know you're stronger in Python 😉

Could be cool to extract this as a constant like REMINDER_EMAIL_PERIOD or REMDER_EMAIL_DELAY. It could be a top level const

Choose a reason for hiding this comment

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

Re-reading this logic, both sides of the conditional will be truthy if daysOld === daysError. Maybe this could be simplified like...

const daysPastExpiration = daysOld - daysError
if (daysPastExpiration % REMINDER_EMAIL_PERIOD === 0) {

index.js Outdated

expiredKeys.forEach((expiredKey) => {

var compiledExpiredEmail = compile(expiredKeyMailTemplate.toString())

Choose a reason for hiding this comment

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

const and let are preferable in javascript to var with modern js. In these cases, I would use const 😄

More background: https://medium.com/javascript-scene/javascript-es6-var-let-or-const-ba58b8dcde75

index.js Outdated
expiredKeys
}) => {
console.log(expiredKeys)
expiredKeyMailTemplate = await readFileAsync(join(__dirname, './reminderemail.html'))

Choose a reason for hiding this comment

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

Add const declaration 😉

index.js Outdated
keyToRotate: expiredKey
})
var msg = {
to: keyListInfo[expiredKey].recipients.map(recipient => {return recipient.email}),

Choose a reason for hiding this comment

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

js tip: this could omit the {} and return: recipients.map(recipient => recipient.email)

@kiriappeee
Copy link
Member Author

thanks so much for the comments @djfarrelly . Still very new to the Javascript world 😁

@kiriappeee
Copy link
Member Author

Hey @djfarrelly . Just pushed the changes for this. It now matches the eslint/airbnb spec. I also learnt a ton more about asynchronous programming. Pretty neat. The whole job runs a lot faster now.

@kiriappeee
Copy link
Member Author

Deployed and testing with tomorrow's job

Base automatically changed from master to main January 19, 2021 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants