@mitre/hdf-generators
v3.1.0
Published
Generate InSpec profile stubs from HDF Baseline definitions
Readme
@mitre/hdf-generators
Generate InSpec profile stubs from HDF Baseline definitions.
What it does
Takes an HDF Baseline JSON document (requirement definitions with metadata, descriptions, and tags) and generates a complete InSpec profile directory structure:
inspec.yml— profile metadata (name, maintainer, license, version, platform supports)controls/*.rb— one control file per requirement withdescribeblocks, tags, and impact
This bridges from HDF's tool-agnostic baseline format to InSpec's executable compliance-as-code format.
Relationship to other packages
| Package | Relationship |
|---------|-------------|
| hdf-schema | Provides the HDFBaseline type that generators consume |
| hdf-converters | Converters produce baselines (e.g., XCCDF benchmark → HDF baseline) that generators can then turn into InSpec profiles |
| hdf-cli | hdf generate inspec-profile command wraps this library |
| hdf-mappings | Baselines may contain NIST/CCI tags from hdf-mappings |
Installation
npm install @mitre/hdf-generatorsUsage (TypeScript)
import { generateInSpecProfile } from '@mitre/hdf-generators';
import type { HDFBaseline } from '@mitre/hdf-schema';
const baseline: HDFBaseline = JSON.parse(fs.readFileSync('baseline.json', 'utf8'));
const profile = generateInSpecProfile(baseline, {
maintainer: 'MITRE SAF',
copyright: 'MITRE Corporation',
license: 'Apache-2.0',
});
// profile.inspecYml — string content for inspec.yml
// profile.controls — Map<string, string> of filename → Ruby control codeIndividual stubs
import { generateControlStub, generateInSpecYml, escapeQuotes } from '@mitre/hdf-generators';
// Generate a single control file
const ruby = generateControlStub(requirement);
// Generate inspec.yml
const yml = generateInSpecYml(baseline, { maintainer: 'Team', license: 'Apache-2.0' });Usage (Go)
import generators "github.com/mitre/hdf-generators"
profile := generators.GenerateInSpecProfile(baseline, generators.ProfileMetadata{
Maintainer: "MITRE SAF",
License: "Apache-2.0",
})
// profile.InspecYml — string
// profile.Controls — map[string]stringCLI usage
hdf generate inspec-profile baseline.json output-dir/
hdf generate inspec-profile baseline.json output-dir/ --maintainer "MITRE SAF"
hdf generate inspec-profile baseline.json output-dir/ --single-fileLicense
Apache-2.0 © MITRE Corporation
