From edbb7ff55f13d4d3cc7a9d2622e742a14b450182 Mon Sep 17 00:00:00 2001 From: "George M. Dias" Date: Tue, 22 Oct 2024 11:59:48 -0500 Subject: [PATCH] Removed console logs in inspec_profile.ts, fixed yml format. (#2987) Co-authored-by: Daniel Medina --- src/commands/generate/inspec_profile.ts | 37 ++++++++++++++----------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/commands/generate/inspec_profile.ts b/src/commands/generate/inspec_profile.ts index 933116a6b..9e42f3854 100644 --- a/src/commands/generate/inspec_profile.ts +++ b/src/commands/generate/inspec_profile.ts @@ -9,6 +9,7 @@ import Profile from '@mitre/inspec-objects/lib/objects/profile' import {BaseCommand} from '../../utils/oclif/baseCommand' import {Logger} from 'winston' import _ from 'lodash' +import YAML from 'yaml' export default class InspecProfile extends BaseCommand { static readonly usage = @@ -512,22 +513,26 @@ DISA STIGs are published by DISA IASE, see: https://iase.disa.mil/Pages/privacy_ } function generateYaml(profile: Profile, outDir: string, logger: Logger) { - console.log(`profile.supports.length is: ${profile.supports.length}`) - console.log(`profile.depends.length is: ${profile.depends.length}`) - const inspecYmlContent = -`name: ${profile.name} -title: ${profile.title} -maintainer: ${profile.maintainer} -copyright: ${profile.copyright} -copyright_email: ${profile.copyright_email} -license: ${profile.license} -summary: ${profile.summary} -description: ${profile.description} -version: ${profile.version} -supports: ${(profile.supports.length === 0) ? '[]' : profile.supports} -depends: ${(profile.depends.length === 0) ? '[]' : JSON.stringify(profile.depends, null, 2)} -inspec_version: "${profile.inspec_version}" -` + // ---------------------------------------------------------------------- + // NOTE: Not using the profile.createInspecYaml() as it does not wrap the + // inspect_version in double quotes (the format is ~>#.#). Use this + // function until ts-object.ts method is fixed + + const inspecYmlContent = YAML.stringify({ + name: profile.name, + title: profile.title, + maintainer: profile.maintainer, + copyright: profile.copyright, + copyright_email: profile.copyright_email, + license: profile.license, + summary: profile.summary, + description: profile.description, + version: profile.version, + supports: profile.supports, + depends: profile.depends, + inspec_version: YAML.stringify(`${profile.inspec_version}`, {defaultStringType: 'QUOTE_DOUBLE'}), + }) + fs.writeFile(path.join(outDir, 'inspec.yml'), inspecYmlContent, err => { if (err) { logger.error(`Error saving the inspec.yml file to: ${outDir}. Cause: ${err}`)