blackstork-io / fabric

An open-source command-line tool for cybersecurity reporting automation and a configuration language for reusable templates. Reporting-as-Code
https://blackstork.io/fabric/
Apache License 2.0
12 stars 0 forks source link

Add a function to load the content of the local file #203

Closed traut closed 1 week ago

traut commented 1 week ago

Background

Some data manipulations require a lot of JQ code. Writing it inline in the template is not convenient, so it would be great to be able to load JQ code from local files.

Design

Add from_file() HCL function that accepts a file path and returns the contents of the file as string (the function expects text)

The example of the use-case would be:

document "test" {

  vars {
    items = ["a", "b", "c"]
  }

  content text {
    local_var = query_jq(from_file("./query.jq"))
    value = "Length: {{ .vars.local }}"
  }
}

with query.jq:

.vars.items | length

To simplify the logic, from_file would resolve the relative path from the directory where Fabric is executed