Skip to content

Commit

Permalink
Merge pull request #10 from gocsaf/limits
Browse files Browse the repository at this point in the history
Use the maximum size of arrays specified in limits.json
  • Loading branch information
s-l-teichmann authored Jan 22, 2025
2 parents 5992b26 + b8a6582 commit 78ce159
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 63 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ named `csaf-0.json` through `csaf-99.json`:
go run cmd/fakedoc/main.go --template template.toml -n 100 -o 'csaf-{{$}}.json'
```

To generate large documents, one can use the something like this:

``` shell
go run cmd/fakedoc/main.go -o random-csaf.json -l limits.json --force-max-size
```

With the `-l limits.json` option, fakedoc loads information about the
maximum lengths of arrays, strings and URIs from the `limits.json` file.
If loaded the maximum lenghts of arrays are taken from this file (it's
only implemented for arrays so far). By default these maximum values are
multiplied by 0.00001 to avoid generating exceedingly large files. This
factor can be set with the `--size` option. With the `--force-max-size`
option, fakedoc tries to make arrays as large as their maximum length.

How big the files will actually be depends not only on the length of the
arrays but also on which parts of the document are actually generated.


## License
Expand Down
17 changes: 16 additions & 1 deletion cmd/fakedoc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ Output JSON should be formatted.

limitsDocumentation = `
Guidance on the Size of CSAF Documents.
`

sizeFactorDocumentation = `
Factor by which to multiply the maxima given in the limits file.
`

forceMaxSizeDocumentation = `
Try to force size of arrays to their maxiumum as defined in the limits
file and modified by the size factor.
`
)

Expand All @@ -63,6 +72,8 @@ func main() {
var (
templatefile string
limitsfile string
sizeFactor float64
forceMaxSize bool
seed string
outputfile string
numOutputs int
Expand All @@ -71,6 +82,8 @@ func main() {

flag.StringVar(&templatefile, "template", "", "template file")
flag.StringVar(&limitsfile, "l", "", limitsDocumentation)
flag.Float64Var(&sizeFactor, "size", 0.00001, sizeFactorDocumentation)
flag.BoolVar(&forceMaxSize, "force-max-size", false, forceMaxSizeDocumentation)
flag.StringVar(&seed, "seed", "", seedDocumentation)
flag.StringVar(&outputfile, "o", "", outputDocumentation)
flag.IntVar(&numOutputs, "n", 1, numOutputDocumentation)
Expand All @@ -93,13 +106,15 @@ func main() {
check(generate(
templatefile, rng,
outputfile, limitsfile,
sizeFactor, forceMaxSize,
numOutputs, formatted))
}

func generate(
templatefile string,
rng *rand.Rand,
outputfile, limitsfile string,
sizeFactor float64, forceMaxSize bool,
numOutputs int,
formatted bool,
) error {
Expand All @@ -123,7 +138,7 @@ func generate(
}
}

generator := fakedoc.NewGenerator(templ, limits, rng)
generator := fakedoc.NewGenerator(templ, limits, sizeFactor, forceMaxSize, rng)

if numOutputs == 1 {
return generateToFile(generator, outputfile, formatted)
Expand Down
Loading

0 comments on commit 78ce159

Please sign in to comment.