Skip to content

Commit

Permalink
export inspecJS function for converting impact into severity
Browse files Browse the repository at this point in the history
Signed-off-by: Kaden Emley <[email protected]>
  • Loading branch information
kemley76 committed Jul 10, 2024
1 parent d929425 commit 65237ef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
13 changes: 2 additions & 11 deletions libs/inspecjs/src/compat_impl/compat_inspec_1_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
HDFControlSegment,
SegmentStatus,
Severity,
convertImpactToSeverity,
severities
} from '../compat_wrappers';
import {
Expand Down Expand Up @@ -174,17 +175,7 @@ abstract class HDFControl10 implements HDFControl {
return raw.tags['severity'];

// otherwise, compute severity with impact
if (raw.impact < 0.1) {
return 'none';
} else if (raw.impact < 0.4) {
return 'low';
} else if (raw.impact < 0.7) {
return 'medium';
} else if (raw.impact < 0.9) {
return 'high';
} else {
return 'critical';
}
return convertImpactToSeverity(raw.impact);
}
}

Expand Down
14 changes: 14 additions & 0 deletions libs/inspecjs/src/compat_wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ export type SegmentStatus =
| 'error'
| 'no_status';

export function convertImpactToSeverity(impact: number): Severity {
if (impact < 0.1) {
return 'none';
} else if (impact < 0.4) {
return 'low';
} else if (impact < 0.7) {
return 'medium';
} else if (impact < 0.9) {
return 'high';
} else {
return 'critical';
}
}

/**
* This interface acts as a polyfill on controls for our HDF "guaranteed" derived types, to provide a stable
* method for acessing their properties across different schemas.
Expand Down
5 changes: 3 additions & 2 deletions libs/inspecjs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Our foreign package API.

// Export types
// Export types and helper functions
export {
ControlStatus,
controlStatuses,
Expand All @@ -13,7 +13,8 @@ export {
severities,
Severity,
titleCasedSeverities,
TitleCasedSeverity
TitleCasedSeverity,
convertImpactToSeverity
} from './compat_wrappers';
// Export Conversion functions
export * from './context';
Expand Down

0 comments on commit 65237ef

Please sign in to comment.