Skip to content

Commit 90d682e

Browse files
Kasun KodagodaKasun Kodagoda
Kasun Kodagoda
authored and
Kasun Kodagoda
committed
Used the new logger implementation.
1 parent 56f699e commit 90d682e

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

BuildTask/ssl-labs-test/SslLabsService.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { inject, injectable } from 'inversify';
44

55
import { ITaskInput } from './interfaces/ITaskInput';
66
import { ISslLabsService } from './interfaces/ISslLabsService';
7+
import { ILogger } from './interfaces/ILogger';
78

89
import { CertificateGrade, CertificateGradeScore } from './Constants';
910

@@ -12,11 +13,14 @@ import TYPES from './di/types';
1213
@injectable()
1314
export class SslLabsService implements ISslLabsService {
1415
private _taskInput: ITaskInput;
16+
private _logger: ILogger;
1517

1618
constructor(
17-
@inject(TYPES.ITaskInput) taskInput: ITaskInput
19+
@inject(TYPES.ITaskInput) taskInput: ITaskInput,
20+
@inject(TYPES.ILogger) logger: ILogger
1821
) {
1922
this._taskInput = taskInput;
23+
this._logger = logger;
2024
}
2125

2226
executeSslTest(): Promise<any> {
@@ -51,6 +55,8 @@ export class SslLabsService implements ISslLabsService {
5155
reject('SSLLabs Scan Result is null or undefined');
5256
}
5357

58+
this._logger.logDebug(`SSLResult endpoint length: ${sslResult.endpoints.length}`);
59+
5460
if (sslResult.endpoints.length > 0) {
5561
const endpoint: any = sslResult.endpoints[0];
5662
const gradeScore: Number = this.convertCertificateGradeToNumber(endpoint.grade);
@@ -73,16 +79,18 @@ export class SslLabsService implements ISslLabsService {
7379
reject('SSLLabs Scan Result is null or undefined');
7480
}
7581

82+
this._logger.logDebug(`SSLResult endpoint length: ${sslResult.endpoints.length}`);
83+
7684
if (sslResult.endpoints.length > 0) {
7785
const endpoint: any = sslResult.endpoints[0];
7886

7987
const expDate = Number(endpoint.details.cert.notAfter);
80-
console.log(`Certificate expire date: ${new Date(expDate)}`);
88+
this._logger.logConsole(`Certificate expire date: ${new Date(expDate)}`);
8189

8290
const currDate = Date.now();
8391
const singleDay = 24 * 60 * 60 * 1000;
8492
const dateDiff = Math.round(Math.abs((expDate - currDate) / singleDay));
85-
console.log(`Days till certificate expires: ${dateDiff}`);
93+
this._logger.logConsole(`Days till certificate expires: ${dateDiff}`);
8694

8795
resolve(dateDiff);
8896

@@ -97,7 +105,7 @@ export class SslLabsService implements ISslLabsService {
97105
}
98106

99107
private convertCertificateGradeToNumber(grade: string): Number {
100-
console.log(`Certificate Grade: ${grade}`);
108+
this._logger.logConsole(`Certificate Grade: ${grade}`);
101109

102110
let gradeScore: Number = 0;
103111
switch (grade) {

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import TYPES from './di/types';
77
import { AlertMode } from './Constants';
88
import { ISslLabsService } from './interfaces/ISslLabsService';
99
import { ITaskInput } from './interfaces/ITaskInput';
10+
import { ILogger } from './interfaces/ILogger';
1011

1112
Task.setResourcePath(path.join(__dirname, 'task.json'));
1213

@@ -16,22 +17,23 @@ async function run(): Promise<string> {
1617

1718
const taskInput: ITaskInput = container.get<ITaskInput>(TYPES.ITaskInput);
1819
const sslLabsService: ISslLabsService = container.get<ISslLabsService>(TYPES.ISslLabsService);
20+
const logger: ILogger = container.get<ILogger>(TYPES.ILogger);
1921

20-
Task.debug(taskInput.toJSON());
21-
Task.debug('Executing SSL Labs Scan with the given inputs');
22-
console.log(`Starting SSL Labs Scan for the hostname: ${taskInput.Hostname}`);
22+
logger.logDebug(taskInput.toJSON());
23+
logger.logDebug('Executing SSL Labs Scan with the given inputs');
24+
logger.logConsole(`Starting SSL Labs Scan for the hostname: ${taskInput.Hostname}`);
2325

24-
const scanResult = await sslLabsService.executeSslTest();
25-
console.log('Scan Completed...');
26+
const scanResult: any = await sslLabsService.executeSslTest();
27+
logger.logConsole('Scan Completed...');
2628

2729

2830
// Check for Verifications
2931
if (taskInput.EnableVerification) {
30-
console.log(`Verifications are Enabled with the Alert Mode: ${taskInput.AlertMode}`);
32+
logger.logConsole(`Verifications are Enabled with the Alert Mode: ${taskInput.AlertMode}`);
3133
const certGradeScore = await sslLabsService.getSslCertificateGrade(scanResult);
3234

3335
if (Number(taskInput.MinimumCertGrade) > certGradeScore) {
34-
console.log('Minimum certifiate grade threshold exceeded. Executing Alert');
36+
logger.logConsole('Minimum certifiate grade threshold exceeded. Executing Alert');
3537
// If certificate grade threshold is passed
3638
switch (taskInput.AlertMode) {
3739
case AlertMode.BREAK_BUILD:
@@ -45,11 +47,11 @@ async function run(): Promise<string> {
4547
}
4648

4749
if (taskInput.EnableExpirationAlert) {
48-
console.log('Certificate expiration alerts Enabled.');
50+
logger.logConsole('Certificate expiration alerts Enabled.');
4951
const daysTillExpire: number = await sslLabsService.timeTillCertificateExpiration(scanResult);
5052

5153
if (daysTillExpire < taskInput.DaysBeforeExpiration) {
52-
console.log('Minimum certifiate expire threshold exceeded. Executing Alert');
54+
logger.logConsole('Minimum certifiate expire threshold exceeded. Executing Alert');
5355
switch (taskInput.AlertMode) {
5456
case AlertMode.BREAK_BUILD:
5557
throw new Error(`SSL certificate is nearing expireation and will expire in ${daysTillExpire} Days.`);

0 commit comments

Comments
 (0)