diff --git a/src/main/kotlin/gov/nist/secauto/oscal/tools/server/OscalCommandExecutor.kt b/src/main/kotlin/gov/nist/secauto/oscal/tools/server/OscalCommandExecutor.kt index a31ab83..8d4d84f 100644 --- a/src/main/kotlin/gov/nist/secauto/oscal/tools/server/OscalCommandExecutor.kt +++ b/src/main/kotlin/gov/nist/secauto/oscal/tools/server/OscalCommandExecutor.kt @@ -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, @@ -39,6 +40,7 @@ open class OscalCommandExecutor( protected val logger: Logger = LogManager.getLogger(this::class.java) protected open val commands: Map ICommand> = mapOf( "validate" to ::ValidateCommand, + "validate-metaschema" to ::ValidateModuleCommand, "convert" to ::ConvertCommand, "query" to ::QueryCommand, "resolve-profile" to ::ResolveCommand diff --git a/src/main/kotlin/gov/nist/secauto/oscal/tools/server/OscalVerticle.kt b/src/main/kotlin/gov/nist/secauto/oscal/tools/server/OscalVerticle.kt index 67a546b..73c3320 100644 --- a/src/main/kotlin/gov/nist/secauto/oscal/tools/server/OscalVerticle.kt +++ b/src/main/kotlin/gov/nist/secauto/oscal/tools/server/OscalVerticle.kt @@ -180,6 +180,7 @@ 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 @@ -187,7 +188,14 @@ class OscalVerticle : CoroutineVerticle() { 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)) } @@ -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)) @@ -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) diff --git a/src/main/resources/webroot/openapi.yaml b/src/main/resources/webroot/openapi.yaml index 137fa98..af44036 100644 --- a/src/main/resources/webroot/openapi.yaml +++ b/src/main/resources/webroot/openapi.yaml @@ -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 @@ -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