chore: more refactoring and cleanup

This commit is contained in:
David Allen 2025-04-23 18:33:09 -06:00
parent aecb56971d
commit 844ce3c3e0
Signed by: towk
GPG key ID: 0430CDBE22619155
3 changed files with 29 additions and 33 deletions

View file

@ -205,26 +205,19 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams) ([]map[strin
// write data to file if output path is set using set format
if outputPath != "" {
switch params.Format {
case "hive":
var (
finalPath = fmt.Sprintf("./%s/%s/%d.json", outputPath, data["ID"], time.Now().Unix())
finalDir = filepath.Dir(finalPath)
)
// if it doesn't, make the directory and write file
err = os.MkdirAll(finalDir, 0o777)
if err == nil { // no error
err = os.WriteFile(path.Clean(finalPath), body, os.ModePerm)
if err != nil {
log.Error().Err(err).Msgf("failed to write collect output to file")
}
} else { // error is set
log.Error().Err(err).Msg("failed to make directory for collect output")
var (
finalPath = fmt.Sprintf("./%s/%s/%d.json", outputPath, data["ID"], time.Now().Unix())
finalDir = filepath.Dir(finalPath)
)
// if it doesn't, make the directory and write file
err = os.MkdirAll(finalDir, 0o777)
if err == nil { // no error
err = os.WriteFile(path.Clean(finalPath), body, os.ModePerm)
if err != nil {
log.Error().Err(err).Msgf("failed to write collect output to file")
}
case "json":
case "yaml":
default:
} else { // error is set
log.Error().Err(err).Msg("failed to make directory for collect output")
}
}