diff --git a/package-lock.json b/package-lock.json index 4235450..92da71c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,6 @@ "@dotcom-reliability-kit/logger": "^3.0.3", "aws-sdk": "^2.6.10", "fetchres": "^1.5.1", - "moment": "^2.29.4", "ms": "^2.0.0", "node-fetch": "^2.6.7" }, @@ -7685,14 +7684,6 @@ "integrity": "sha1-z4tP9PKWQGdNbN0CsOO8UjwrvcA=", "dev": true }, - "node_modules/moment": { - "version": "2.29.4", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", - "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", - "engines": { - "node": "*" - } - }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -18570,11 +18561,6 @@ "integrity": "sha1-z4tP9PKWQGdNbN0CsOO8UjwrvcA=", "dev": true }, - "moment": { - "version": "2.29.4", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", - "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==" - }, "ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", diff --git a/package.json b/package.json index 01b0ed0..f8b7d6f 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,6 @@ "@dotcom-reliability-kit/logger": "^3.0.3", "aws-sdk": "^2.6.10", "fetchres": "^1.5.1", - "moment": "^2.29.4", "ms": "^2.0.0", "node-fetch": "^2.6.7" }, diff --git a/src/checks/cloudWatchThreshold.check.js b/src/checks/cloudWatchThreshold.check.js index cecbd16..cba3d6a 100644 --- a/src/checks/cloudWatchThreshold.check.js +++ b/src/checks/cloudWatchThreshold.check.js @@ -1,7 +1,6 @@ 'use strict'; const AWS = require('aws-sdk'); -const moment = require('moment'); const logger = require('@dotcom-reliability-kit/logger'); const status = require('./status'); const Check = require('./check'); @@ -32,11 +31,12 @@ class CloudWatchThresholdCheck extends Check { generateParams() { // use a larger window when gathering stats, because CloudWatch // can take its sweet time with populating new datapoints. - let timeWindow = this.samplePeriod * 1.5; - const now = moment(); + let timeWindowInMs = this.samplePeriod * 1.5 * 1000; + const now = new Date(); + const startTime = new Date(now.getTime() - timeWindowInMs); return { EndTime: now.toISOString(), - StartTime: now.subtract(timeWindow, 'seconds').toISOString(), + StartTime: startTime.toISOString(), MetricName: this.cloudWatchMetricName, Namespace: this.cloudWatchNamespace, Period: this.samplePeriod, diff --git a/src/checks/fastlyKeyExpiration.check.js b/src/checks/fastlyKeyExpiration.check.js index 0bbd089..24d1335 100644 --- a/src/checks/fastlyKeyExpiration.check.js +++ b/src/checks/fastlyKeyExpiration.check.js @@ -1,9 +1,10 @@ const fetch = require('node-fetch'); -const moment = require('moment'); const logger = require('@dotcom-reliability-kit/logger'); const Check = require('./check'); const status = require('./status'); +const twoWeeksInDays = 2 * 7; + const fastlyApiEndpoint = 'https://api.fastly.com/tokens/self'; const defaultPanicGuide = 'Generate a new key in your own Fastly account with the same permissions and update it in Vault or your app'; @@ -79,8 +80,15 @@ class FastlyKeyExpirationCheck extends Check { } parseStringDate(stringDate) { - const date = moment(stringDate, 'YYYY-MM-DDTHH:mm:ssZ'); - if (!date.isValid()) { + let dateIsValid = true; + let date; + try { + date = new Date(stringDate); + dateIsValid = !Number.isNaN(date.getDate()); + } catch (error) { + dateIsValid = false; + } + if (!dateIsValid) { logger.warn(`Invalid Fastly Key expiration date ${stringDate}`); this.setState(this.states.FAILED_DATE); throw new Error('Invalid date'); @@ -95,12 +103,13 @@ class FastlyKeyExpirationCheck extends Check { } checkExpirationDate(expirationDate) { - const now = moment(); - const limitDate = moment().add(2, 'weeks'); + const now = new Date(); + const limitDate = new Date(); + limitDate.setDate(now.getDate() + twoWeeksInDays); switch (true) { - case expirationDate.isAfter(limitDate): + case expirationDate > limitDate: return this.states.PASSED; - case expirationDate.isBefore(now): + case expirationDate <= now: return this.states.FAILED_URGENT_VALIDATION; default: return this.states.FAILED_VALIDATION;