Skip to content

Commit 28e0c82

Browse files
committed
Added logging messages to the task.
1 parent e135fe8 commit 28e0c82

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

BuildTask/ssl-labs-test/SslLabsService.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { CertificateGrade, CertificateGradeScore } from './Constants';
21
import * as SslLabs from 'node-ssllabs';
2+
import { Options } from 'node-ssllabs';
33
import { inject, injectable } from 'inversify';
44

55
import { ITaskInput } from './interfaces/ITaskInput';
66
import { ISslLabsService } from './interfaces/ISslLabsService';
77

8-
import { Options } from 'node-ssllabs';
9-
import { TaskInput } from './TaskInput';
8+
import { CertificateGrade, CertificateGradeScore } from './Constants';
109

1110
import TYPES from './di/types';
1211

@@ -78,9 +77,12 @@ export class SslLabsService implements ISslLabsService {
7877
const endpoint: any = sslResult.endpoints.shift();
7978

8079
const expDate = Number(endpoint.details.cert.notAfter);
80+
console.log(`Certificate expire date: ${new Date(expDate)}`);
81+
8182
const currDate = Date.now();
8283
const singleDay = 24 * 60 * 60 * 1000;
8384
const dateDiff = Math.round(Math.abs((expDate - currDate) / singleDay));
85+
console.log(`Days till certificate expires: ${dateDiff}`);
8486

8587
resolve(dateDiff);
8688

@@ -95,6 +97,8 @@ export class SslLabsService implements ISslLabsService {
9597
}
9698

9799
private convertCertificateGradeToNumber(grade: string): Number {
100+
console.log(`Certificate Grade: ${grade}`);
101+
98102
let gradeScore: Number = 0;
99103
switch (grade) {
100104
case CertificateGrade.A_PLUS:

BuildTask/ssl-labs-test/ssl-labs-test.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@ async function run(): Promise<string> {
1919

2020
Task.debug(taskInput.toJSON());
2121
Task.debug('Executing SSL Labs Scan with the given inputs');
22+
console.log(`Starting SSL Labs Scan for the hostname: ${taskInput.Hostname}`);
2223

2324
const scanResult = await sslLabsService.executeSslTest();
25+
console.log('Scan Completed...');
26+
2427

2528
// Check for Verifications
2629
if (taskInput.EnableVerification) {
30+
console.log(`Verifications are Enabled with the Alert Mode: ${taskInput.AlertMode}`);
2731
const certGradeScore = await sslLabsService.getSslCertificateGrade(scanResult);
2832

2933
if (Number(taskInput.MinimumCertGrade) > certGradeScore) {
30-
34+
console.log('Minimum certifiate grade threshold exceeded. Executing Alert');
3135
// If certificate grade threshold is passed
3236
switch (taskInput.AlertMode) {
3337
case AlertMode.BREAK_BUILD:
@@ -41,12 +45,14 @@ async function run(): Promise<string> {
4145
}
4246

4347
if (taskInput.EnableExpirationAlert) {
44-
const timeDiff: number = await sslLabsService.timeTillCertificateExpiration(scanResult);
48+
console.log('Certificate expiration alerts Enabled.');
49+
const daysTillExpire: number = await sslLabsService.timeTillCertificateExpiration(scanResult);
4550

46-
if (timeDiff < taskInput.DaysBeforeExpiration) {
51+
if (daysTillExpire < taskInput.DaysBeforeExpiration) {
52+
console.log('Minimum certifiate expire threshold exceeded. Executing Alert');
4753
switch (taskInput.AlertMode) {
4854
case AlertMode.BREAK_BUILD:
49-
throw new Error(`SSL certificate is nearing expireation and will expire in ${timeDiff} Days.`);
55+
throw new Error(`SSL certificate is nearing expireation and will expire in ${daysTillExpire} Days.`);
5056

5157
case AlertMode.SET_VARIABLE:
5258
Task.setVariable(taskInput.VariableName, taskInput.VariableContent, false);
@@ -65,11 +71,9 @@ async function run(): Promise<string> {
6571

6672
run()
6773
.then((res: string) => {
68-
console.log(res);
6974
Task.setResult(Task.TaskResult.Succeeded, res);
7075
})
7176
.catch((err: any) => {
7277
const msg = `Task Failed. Error: ${JSON.stringify(err)}`;
73-
console.log(msg);
7478
Task.setResult(Task.TaskResult.Failed, msg);
7579
});

0 commit comments

Comments
 (0)