Skip to content

Commit

Permalink
Removed console logs in inspec_profile.ts, fixed yml format. (#2987)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Medina <[email protected]>
  • Loading branch information
georgedias and DMedina6 authored Oct 22, 2024
1 parent b90f11a commit edbb7ff
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/commands/generate/inspec_profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof InspecProfile> {
static readonly usage =
Expand Down Expand Up @@ -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}`)
Expand Down

0 comments on commit edbb7ff

Please sign in to comment.