Skip to content
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

Bump eslint-config-oclif-typescript from 1.0.3 to 3.0.29 #2121

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,911 changes: 1,089 additions & 822 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"@typescript-eslint/eslint-plugin": "~6.15.0",
"eslint": "^8.48.0",
"eslint-config-oclif": "^4.0",
"eslint-config-oclif-typescript": "^1.0.3",
"eslint-config-oclif-typescript": "^3.0.29",
"eslint-plugin-unicorn": "^49.0.0",
"mocha": "^10",
"oclif": "^4",
Expand Down
121 changes: 61 additions & 60 deletions src/commands/attest/apply.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,82 @@
import {Attestation, addAttestationToHDF, parseXLSXAttestations} from '@mitre/hdf-converters'
import {Command, Flags} from '@oclif/core'
import fs from 'fs'
import {ExecJSON} from 'inspecjs'
import {addAttestationToHDF, Attestation, parseXLSXAttestations} from '@mitre/hdf-converters'
import _ from 'lodash'
import yaml from 'yaml'
import fs from 'fs'
import path from 'path'
import yaml from 'yaml'

import {convertFullPathToFilename} from '../../utils/global'

export default class ApplyAttestation extends Command {
static usage = 'attest apply -i <input-hdf-json>... <attestation>... -o <output-hdf-path>'
static description = 'Apply one or more attestation files to one or more HDF results sets'

static description = 'Apply one or more attestation files to one or more HDF results sets'
static examples = [
'saf attest apply -i hdf.json attestation.json -o new-hdf.json',
'saf attest apply -i hdf1.json hdf2.json attestation.xlsx -o outputDir',
]

static examples = [
'saf attest apply -i hdf.json attestation.json -o new-hdf.json',
'saf attest apply -i hdf1.json hdf2.json attestation.xlsx -o outputDir',
]
static flags = {
help: Flags.help({char: 'h'}),
input: Flags.string({char: 'i', description: 'Your input HDF and Attestation file(s)', multiple: true, required: true}),
output: Flags.string({char: 'o', description: 'Output file or folder (for multiple executions)', required: true}),
}

static flags = {
help: Flags.help({char: 'h'}),
input: Flags.string({char: 'i', required: true, multiple: true, description: 'Your input HDF and Attestation file(s)'}),
output: Flags.string({char: 'o', required: true, description: 'Output file or folder (for multiple executions)'}),
}
static usage = 'attest apply -i <input-hdf-json>... <attestation>... -o <output-hdf-path>'

async run() {
const {flags} = await this.parse(ApplyAttestation)
async run() {
const {flags} = await this.parse(ApplyAttestation)

const attestations: Attestation[] = []
const executions: Record<string, ExecJSON.Execution> = {}
const attestations: Attestation[] = []
const executions: Record<string, ExecJSON.Execution> = {}

for (const inputFile of flags.input) {
let inputData
try {
inputData = JSON.parse(fs.readFileSync(inputFile, 'utf8'))
if (Array.isArray(inputData) && inputData.length > 0 && _.get(inputData, '[0].control_id')) {
// We have an attestations JSON
attestations.push(...inputData)
} else if (Array.isArray(_.get(inputData, 'plugins.inspec-reporter-json-hdf.attestations'))) {
// We have a legacy Inspec Tools attestations file
attestations.push(..._.get(inputData, 'plugins.inspec-reporter-json-hdf.attestations'))
} else if ('profiles' in inputData) {
// We have an execution file
executions[convertFullPathToFilename(inputFile)] = inputData
} else {
// Unknown file
console.error(`Unknown input file: ${inputFile}`)
process.exit(1)
}
} catch {
inputData = fs.readFileSync(inputFile, 'utf8')
if (inputFile.toLowerCase().endsWith('xlsx')) {
// We have a spreadsheet
attestations.push(...(await parseXLSXAttestations(fs.readFileSync(inputFile, null))))
} else if (inputFile.toLowerCase().endsWith('yml') || inputFile.toLowerCase().endsWith('yaml')) {
// We have a YAML
attestations.push(...yaml.parse(inputData))
} else {
throw new Error(`Unknown input file: ${inputFile}`)
}
for (const inputFile of flags.input) {
let inputData
try {
inputData = JSON.parse(fs.readFileSync(inputFile, 'utf8'))
if (Array.isArray(inputData) && inputData.length > 0 && _.get(inputData, '[0].control_id')) {
// We have an attestations JSON
attestations.push(...inputData)
} else if (Array.isArray(_.get(inputData, 'plugins.inspec-reporter-json-hdf.attestations'))) {
// We have a legacy Inspec Tools attestations file
attestations.push(..._.get(inputData, 'plugins.inspec-reporter-json-hdf.attestations'))
} else if ('profiles' in inputData) {
// We have an execution file
executions[convertFullPathToFilename(inputFile)] = inputData
} else {
// Unknown file
console.error(`Unknown input file: ${inputFile}`)
process.exit(1)
}
} catch {
inputData = fs.readFileSync(inputFile, 'utf8')
if (inputFile.toLowerCase().endsWith('xlsx')) {
// We have a spreadsheet
attestations.push(...(await parseXLSXAttestations(fs.readFileSync(inputFile, null))))
} else if (inputFile.toLowerCase().endsWith('yml') || inputFile.toLowerCase().endsWith('yaml')) {
// We have a YAML
attestations.push(...yaml.parse(inputData))
} else {
throw new Error(`Unknown input file: ${inputFile}`)
}
}
}

if (Object.entries(executions).length > 1 && !fs.existsSync(flags.output)) {
fs.mkdirSync(flags.output)
}
if (Object.entries(executions).length > 1 && !fs.existsSync(flags.output)) {
fs.mkdirSync(flags.output)
}

if (Object.keys(executions).length === 0) {
throw new Error('Please provide at least one HDF file')
}
if (Object.keys(executions).length === 0) {
throw new Error('Please provide at least one HDF file')
}

for (const [originalFilename, execution] of Object.entries(executions)) {
const applied = addAttestationToHDF(execution, attestations)
if (Object.entries(executions).length <= 1) {
fs.writeFileSync(flags.output, JSON.stringify(applied, null, 2))
} else {
fs.writeFileSync(path.join(flags.output, originalFilename), JSON.stringify(applied, null, 2))
}
for (const [originalFilename, execution] of Object.entries(executions)) {
const applied = addAttestationToHDF(execution, attestations)
if (Object.entries(executions).length <= 1) {
fs.writeFileSync(flags.output, JSON.stringify(applied, null, 2))
} else {
fs.writeFileSync(path.join(flags.output, originalFilename), JSON.stringify(applied, null, 2))
}
}
}
}
Loading
Loading