timoni icon indicating copy to clipboard operation
timoni copied to clipboard

Parse arbitrary JSON or YAML documents as values

Open errordeveloper opened this issue 1 year ago • 6 comments

This would be a follow-up feature to #9. It would be useful to be able to read a JSON or YAML document and pick some paths from it.

I was trying to do this:

package main

import ( 
    "encoding/json"
    "tool/file"
)

imagesFile: file.Read & {
    filename: "images.json"
    contents: string
}

images: json.Unmarshal(imagesFile.contents)

values: {
    imageDigest: "\(images[0].digest)"
}

But it turns out tool/file only works in conjunction with tool/cli, i.e. via cue cmd, as it compromises hermeticity.

So if there could be a way to achieve this in Timoni, it'd be great. It may require creating a custom Go extension to CUE, which would be possible. I do wonder how the hermeticity problem can be addressed.

Is the way JSON and YAML values work as of #51?

I suppose the way to spin this is that results will be reproducible as long as inputs don't change and that CUE prevents users from compromising hermiticity by not allowing reading files and generating either time-variant or random values from their code.

/cc @squaremo

errordeveloper avatar Apr 24 '23 21:04 errordeveloper