npm.io
3.3.2 • Published 3d ago

@mitre/hdf-generators

Licence
Apache-2.0
Version
3.3.2
Deps
1
Size
70 kB
Vulns
0
Weekly
0
Stars
1

@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 with describe blocks, 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-generators

Usage (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 code
Individual 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]string

CLI 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-file

License

Apache-2.0 MITRE Corporation