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

Remove moment #231

Merged
merged 4 commits into from
Mar 22, 2024
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
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
8 changes: 4 additions & 4 deletions src/checks/cloudWatchThreshold.check.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 16 additions & 7 deletions src/checks/fastlyKeyExpiration.check.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
Expand All @@ -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;
Expand Down