-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is extracted from oscalkit project. Similarly as NIST extracted metaschema out of original OSCAL repo, I am extracting metaschema to a separate repo. See: https://github.com/usnistgov/metaschema
- Loading branch information
Showing
7 changed files
with
913 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/gocomply/metaschema | ||
|
||
go 1.13 | ||
|
||
require github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 h1:VHgatEHNcBFEB7inlalqfNqw65aNkM1lGX2yt3NmbS8= | ||
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= |
Submodule OSCAL
added at
4fc172
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/xml" | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/gocomply/metaschema/metaschema" | ||
) | ||
|
||
const ( | ||
oscalRepo = "https://github.com/usnistgov/OSCAL.git" | ||
metaschemaBaseDir = "OSCAL/src/metaschema/%s" | ||
) | ||
|
||
func main() { | ||
rmCmd := exec.Command("rm", "-rf", "OSCAL/") | ||
if err := rmCmd.Run(); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
cloneCmd := exec.Command("git", "clone", "--depth", "1", oscalRepo) | ||
if err := cloneCmd.Run(); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
metaschemaPaths := map[string]string{ | ||
"validation_root": "oscal_metadata_metaschema.xml", | ||
"nominal_catalog": "oscal_control-common_metaschema.xml", | ||
"catalog": "oscal_catalog_metaschema.xml", | ||
"profile": "oscal_profile_metaschema.xml", | ||
"implementation": "oscal_implementation-common_metaschema.xml", | ||
"ssp": "oscal_ssp_metaschema.xml", | ||
"component": "oscal_component_metaschema.xml", | ||
} | ||
|
||
for _, metaschemaPath := range metaschemaPaths { | ||
f, err := os.Open(fmt.Sprintf(metaschemaBaseDir, metaschemaPath)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer f.Close() | ||
|
||
meta, err := decode(f) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if err := metaschema.GenerateTypes(meta); err != nil { | ||
log.Fatalf("Error generating go types for metaschema: %s", err) | ||
} | ||
} | ||
|
||
rmCmd = exec.Command("rm", "-rf", "OSCAL/") | ||
if err := rmCmd.Run(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func decode(r io.Reader) (*metaschema.Metaschema, error) { | ||
var meta metaschema.Metaschema | ||
|
||
d := xml.NewDecoder(r) | ||
|
||
if err := d.Decode(&meta); err != nil { | ||
return nil, fmt.Errorf("Error decoding metaschema: %s", err) | ||
} | ||
|
||
for _, imported := range meta.Import { | ||
if imported.Href == nil { | ||
return nil, fmt.Errorf("import element in %s is missing 'href' attribute", r) | ||
} | ||
imf, err := os.Open(fmt.Sprintf(metaschemaBaseDir, imported.Href.URL.String())) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer imf.Close() | ||
|
||
importedMeta, err := decode(imf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
meta.ImportedMetaschema = append(meta.ImportedMetaschema, *importedMeta) | ||
} | ||
err := meta.LinkDefinitions() | ||
|
||
return &meta, err | ||
} |
Oops, something went wrong.