Skip to content

Commit

Permalink
Merge pull request #30 from metaschema-framework/feature/add-metasche…
Browse files Browse the repository at this point in the history
…ma-validate

if module is metaschema namespace, use built in metaschema validator
  • Loading branch information
wandmagic authored Nov 5, 2024
2 parents bb71af4 + 548891d commit 519ab8c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import gov.nist.secauto.oscal.tools.cli.core.commands.ConvertCommand
import gov.nist.secauto.oscal.tools.cli.core.commands.ValidateCommand
import gov.nist.secauto.oscal.tools.cli.core.commands.ResolveCommand
import gov.nist.secauto.oscal.tools.server.core.commands.QueryCommand
import gov.nist.secauto.metaschema.cli.commands.ValidateModuleCommand

open class OscalCommandExecutor(
protected val command: String,
Expand All @@ -39,6 +40,7 @@ open class OscalCommandExecutor(
protected val logger: Logger = LogManager.getLogger(this::class.java)
protected open val commands: Map<String, () -> ICommand> = mapOf(
"validate" to ::ValidateCommand,
"validate-metaschema" to ::ValidateModuleCommand,
"convert" to ::ConvertCommand,
"query" to ::QueryCommand,
"resolve-profile" to ::ResolveCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,22 @@ class OscalVerticle : CoroutineVerticle() {
val body = ctx.body().asString()
logger.info("Received body: $body")
val flags = ctx.queryParam("flags")
val encodedModule = ctx.queryParam("module").firstOrNull()

if (body.isNotEmpty()) {
// Create a temporary file
val tempFile = Files.createTempFile(oscalDir, "upload", ".tmp")

val tempFilePath = tempFile.toAbsolutePath()
logger.info("Created temporary file: $tempFilePath")
val args = mutableListOf("validate", tempFilePath.toString(),"--show-stack-trace")
var command = "validate"
encodedModule?.let { module ->
if (module == "http://csrc.nist.gov/ns/oscal/metaschema/1.0") {
command = "validate-metaschema"
}
}

val args = mutableListOf(command, tempFilePath.toString(),"--show-stack-trace")
flags.forEach { flag ->
args.add(flagToParam(flag))
}
Expand Down Expand Up @@ -238,11 +246,18 @@ class OscalVerticle : CoroutineVerticle() {
try {
logger.info("Handling Validate request")
val encodedContent = ctx.queryParam("document").firstOrNull()
val encodedModule = ctx.queryParam("module").firstOrNull()
val constraint = ctx.queryParam("constraint")
val flags = ctx.queryParam("flags")
if (encodedContent != null) {
val content = processUrl(encodedContent)
val args = mutableListOf("validate", content, "--show-stack-trace")
var command = "validate"
encodedModule?.let { module ->
if (module == "http://csrc.nist.gov/ns/oscal/metaschema/1.0") {
command = "validate-metaschema"
}
}
val args = mutableListOf(command, content, "--show-stack-trace")
constraint.forEach { constraint_document ->
args.add("-c")
args.add(processUrl(constraint_document))
Expand Down Expand Up @@ -392,7 +407,7 @@ class OscalVerticle : CoroutineVerticle() {
}
mutableArgs.add("-o")
}
if (mutableArgs[0] == "query"){
if (mutableArgs[0] == "query"||mutableArgs[0]=="validate-metaschema"){
mutableArgs.add("-o")
}
mutableArgs.add(sarifFilePath)
Expand Down
14 changes: 14 additions & 0 deletions src/main/resources/webroot/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ paths:
example:
- https://raw.githubusercontent.com/GSA/fedramp-automation/refs/heads/develop/src/validations/constraints/fedramp-external-constraints.xml
- https://raw.githubusercontent.com/GSA/fedramp-automation/refs/heads/develop/src/validations/constraints/fedramp-external-constraints.xml
- in: query
name: module
required: false
schema:
type: string
enum: [http://csrc.nist.gov/ns/oscal/metaschema/1.0,http://csrc.nist.gov/ns/oscal/1.0]
description: URI or NS of metaschema module
- in: query
name: flags
required: false
Expand Down Expand Up @@ -74,6 +81,13 @@ paths:
example:
- https://raw.githubusercontent.com/GSA/fedramp-automation/refs/heads/develop/src/validations/constraints/fedramp-external-constraints.xml
- https://raw.githubusercontent.com/GSA/fedramp-automation/refs/heads/develop/src/validations/constraints/fedramp-external-constraints.xml
- in: query
name: module
required: false
schema:
type: string
enum: [http://csrc.nist.gov/ns/oscal/metaschema/1.0,http://csrc.nist.gov/ns/oscal/1.0]
description: URI or NS of metaschema module
- in: query
name: flags
required: false
Expand Down

0 comments on commit 519ab8c

Please sign in to comment.