docker-archive / oscalkit

NIST OSCAL SDK and CLI
https://docker.github.io/oscalkit/
Other
36 stars 23 forks source link

Generate XML and JSON catalogs from processed profiles #61

Open anweiss opened 5 years ago

anweiss commented 5 years ago

In parallel to #12, we should also include the ability to generate XML and JSON catalogs from profiles that have been processed. This will require a somewhat of a refactor of how we parse prose since we'll need to support substituting <insert> elements in catalogs with the contents of <set-param> elements in profiles as part of this issue.

@minhaj10p going to assign you to this one since you've already implemented most of the processing code via #52. I'm thinking we can create two subcommands off of generate to support this. oscalkit generate code would be used for generating catalog source code as we're already doing via #12. oscalkit generate catalogs would be used for addressing this issue. Thoughts?

minhaj10p commented 5 years ago

@anweiss Is this a good way to replace the Prose inserts? Still need to figure out the recursive part manipulation strategy

// ReplaceInsertParams replaces insert parameters
func (p *Prose) ReplaceInsertParams(parameterID, parameterValue string) error {

    rs := fmt.Sprintf(`<insert param-id="%s">`, parameterID)
    regex, err := regexp.Compile(rs)
    if err != nil {
        return err
    }
    for i := range p.P {
        p.P[i].Raw = regex.ReplaceAllString(p.P[i].Raw, parameterValue)

    }
    for i := range p.OL {
        p.OL[i].Raw = regex.ReplaceAllString(p.OL[i].Raw, parameterValue)
        spew.Dump(p.OL[i].Raw)
    }
    for i := range p.Pre {
        p.Pre[i].Raw = regex.ReplaceAllString(p.Pre[i].Raw, parameterValue)
    }
    for i := range p.UL {
        p.UL[i].Raw = regex.ReplaceAllString(p.UL[i].Raw, parameterValue)
    }
    return nil
}
anweiss commented 5 years ago

@minhaj10p I think this is a good approach. Regex is probably going to be the only suitable way to address this for now.

minhaj10p commented 5 years ago

@anweiss I have added the Prose processing for nested part in the catalog in https://github.com/docker/oscalkit/pull/63

I can append the integration of this in https://github.com/docker/oscalkit/pull/58 once #63 gets approved and merged.