-
Notifications
You must be signed in to change notification settings - Fork 38
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
HTML Export Support #1689
Open
charleshu-8
wants to merge
19
commits into
main
Choose a base branch
from
htmlConverter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
HTML Export Support #1689
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8fb223b
Initial converter
charleshu-8 d2d277e
Merge branch 'main' into htmlConverter
charleshu-8 ebcc222
Merge branch 'main' into htmlConverter
charleshu-8 87a520f
TW import commit
charleshu-8 b973771
Merge branch 'main' into htmlConverter
charleshu-8 0763bfa
Format correct input for html conversion
charleshu-8 2c789bd
Merge branch 'main' into htmlConverter
charleshu-8 8781bb8
Linting
charleshu-8 95087da
Merge branch 'main' into htmlConverter
Amndeep7 6941fc4
Merge branch 'main' into htmlConverter
em-c-rod 699544d
Merge branch 'main' into htmlConverter
kemley76 ba03e25
fix hdf2html conversion
kemley76 171600f
added tests for hdf2html
kemley76 cebb918
update README
kemley76 aee3cc3
Merge branch 'main' into htmlConverter
kemley76 93314d9
update test after hdf2html updates
kemley76 3f9993d
Merge branch 'main' into htmlConverter
kemley76 40c3c8a
update hdf2html tests to ignore autogenerated tailwind css
kemley76 8f43bbc
only remove versions when running hdf2html tests
kemley76 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {Command, Flags} from '@oclif/core' | ||
import fs from 'fs' | ||
import path from 'path' | ||
import {FromHDFToHTMLMapper as Mapper} from '@mitre/hdf-converters' | ||
|
||
// All selectable export types for an HTML export | ||
enum FileExportTypes { | ||
Executive = 'Executive', | ||
Manager = 'Manager', | ||
Administrator = 'Administrator' | ||
} | ||
|
||
export default class HDF2HTML extends Command { | ||
static usage = 'convert hdf2html -i <hdf-scan-results-json>... -o <output-html> [-h]' | ||
|
||
static description = 'Translate an HDF file into a Heimdall Report HTML file' | ||
|
||
static examples = ['saf convert hdf2html -i hdf_input.json -o report.html'] | ||
|
||
static flags = { | ||
help: Flags.help({char: 'h'}), | ||
input: Flags.string({char: 'i', required: true, multiple: true, description: 'Input HDF JSON file'}), | ||
output: Flags.string({char: 'o', required: true, description: 'Output HTML file'}), | ||
} | ||
|
||
async run() { | ||
const {flags} = await this.parse(HDF2HTML) | ||
|
||
const files = [] | ||
for (const file of flags.input) { | ||
// Create (somewhat) unique fileID for html reference | ||
const idCore = path.basename(file).replace(' ', '-') | ||
const idTail1 = Math.random() * 100 | ||
const idTail2 = Math.random() * 100 | ||
|
||
const data = fs.readFileSync(file, 'utf8') | ||
const fileName = path.basename(file) | ||
const fileID = `${idCore}-${idTail1}-${idTail2}` | ||
files.push({data, fileName, fileID}) | ||
} | ||
|
||
const converter = await new Mapper(files, FileExportTypes.Administrator).toHTML('/html/') | ||
fs.writeFileSync(flags.output, converter) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** @type {import('tailwindcss').Config} */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unneeded imports There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HDF to HTML has been refactored to avoid needing tailwind on SAF CLI. Tailwind is all managed by hdf-converters's build system. |
||
|
||
// Lookup constants | ||
const fs = require("fs"); | ||
|
||
// Grabs template and dependencies for HTML export | ||
const files = { | ||
[require.resolve( | ||
"@mitre/hdf-converters/src/converters-from-hdf/html/template.html" | ||
)]: "src/commands/convert/html/template.html", | ||
[require.resolve("tw-elements/dist/js/tw-elements.umd.min.js")]: | ||
"src/commands/convert/html/tw-elements.min.js", | ||
}; | ||
for (const file in files) { | ||
fs.copyFile(file, files[file], (err) => { | ||
if (err) { | ||
throw err; | ||
} | ||
}); | ||
} | ||
|
||
module.exports = { | ||
content: [ | ||
"./src/commands/convert/html/template.html", | ||
"./node_modules/tw-elements/dist/js/**/*.js", | ||
], | ||
theme: { | ||
extend: {}, | ||
}, | ||
plugins: [require("tw-elements/dist/plugin.cjs")], | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not add an input flag for report type rather than defaulting to Administrator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done