Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial structure for cpg native queries and and a small example #865

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/features.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ val enablePluginSupport: Boolean by rootProject.extra

dependencies {
if (enablePluginSupport) runtimeOnly(project(":codyze-plugins"))
}
}
1 change: 1 addition & 0 deletions codyze-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies {
implementation(projects.codyzeCore)
implementation(projects.codyzeBackends.cpg)
implementation(projects.codyzeSpecificationLanguages.coko.cokoDsl)
implementation(projects.codyzeSpecificationLanguages.cpgNative)

implementation(libs.clikt)
implementation(libs.koin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import de.fraunhofer.aisec.codyze.core.executor.ExecutorCommand
import de.fraunhofer.aisec.codyze.core.output.OutputBuilder
import de.fraunhofer.aisec.codyze.core.output.SarifBuilder
import de.fraunhofer.aisec.codyze.core.plugin.Plugin
import de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native.CPGQuerySubcommand
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.dsl.cli.CokoSubcommand
import org.koin.core.module.dsl.factoryOf
import org.koin.dsl.bind
Expand All @@ -42,6 +43,7 @@ val backendCommands = module {
* Each [Executor] must provide a [ExecutorCommand] to be selectable in the CLI.
*/
val executorCommands = module {
factoryOf(::CPGQuerySubcommand) bind(ExecutorCommand::class)
factoryOf(::CokoSubcommand) bind(ExecutorCommand::class)
}

Expand Down
38 changes: 38 additions & 0 deletions codyze-specification-languages/cpg-native/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
id("documented-module")
id("publish")
}

dependencies {
implementation(projects.codyzeCore)
implementation(projects.codyzeSpecificationLanguages.coko.cokoCore)
implementation(projects.codyzeBackends.cpg) // used only for the CokoScript plugin block configuration
implementation(libs.bundles.cpg)
implementation(libs.kotlin.reflect)

implementation(libs.sarif4k)
implementation(libs.koin)
implementation(libs.clikt)

// For testing with koin
// kotlin-test-junit has to be excluded because it is loaded by "documented-module" plugin
testImplementation(libs.koin.test) {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-test-junit")
}
testImplementation(libs.koin.junit5) {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-test-junit")
}
testImplementation(libs.mockk)
testImplementation(libs.bundles.cpg)
}

publishing {
publications {
named<MavenPublication>(name) {
pom {
name.set("Codyze Specification Language Native CPG Query DSL")
description.set("Queries with native CPG DSL for Codyze")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native

import de.fraunhofer.aisec.codyze.core.executor.ExecutorConfiguration
import io.github.oshai.kotlinlogging.KotlinLogging

private val logger = KotlinLogging.logger { }

Check warning on line 21 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryConfiguration.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryConfiguration.kt#L21

Added line #L21 was not covered by tests

data class CPGQueryConfiguration(
val runQueries: Boolean // Queries may be turned of, if all executors are run and queries shoul be excluded

Check warning on line 24 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryConfiguration.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryConfiguration.kt#L23-L24

Added lines #L23 - L24 were not covered by tests
) : ExecutorConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native

import de.fraunhofer.aisec.codyze.backends.cpg.CPGBackend
import de.fraunhofer.aisec.codyze.core.executor.Executor
import de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native.queries.CPGQuery
import de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native.queries.ExampleQuery
import io.github.detekt.sarif4k.Run
import io.github.oshai.kotlinlogging.KotlinLogging
import java.io.FileOutputStream
import java.io.PrintStream

private val logger = KotlinLogging.logger {}

Check warning on line 27 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L27

Added line #L27 was not covered by tests

/**
* The [Executor] to run natively defined CPG queries on the cpg backend, generating Sarif output
*/

class CPGQueryExecutor(private val configuration: CPGQueryConfiguration, private val backend: CPGBackend) :

Check warning

Code scanning / detekt

Property is unused and should be removed. Warning

Private property configuration is unused.

Check warning on line 33 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L33

Added line #L33 was not covered by tests
Executor {
private val queries: MutableList<CPGQuery> = mutableListOf()

Check warning on line 35 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L35

Added line #L35 was not covered by tests

init {
queries.add(ExampleQuery())

Check warning on line 38 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L37-L38

Added lines #L37 - L38 were not covered by tests
}

override fun evaluate(): Run {
logger.info { "Running CPG Queries" }
val findings: MutableMap<CPGQuery, List<CpgQueryFinding>> = mutableMapOf()

Check warning on line 43 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L42-L43

Added lines #L42 - L43 were not covered by tests

queries.forEach {
findings.put(it, it.query(backend))

Check warning on line 46 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L45-L46

Added lines #L45 - L46 were not covered by tests
}
val informationExtractor = TSFIInformationExtractor()
informationExtractor.extractInformation(backend.cpg)

Check warning on line 49 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L48-L49

Added lines #L48 - L49 were not covered by tests

informationExtractor.printInformation(
XMLFormatter(),
PrintStream(FileOutputStream("sf.xml")),
PrintStream(FileOutputStream("tsfi.xml"))

Check warning on line 54 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L51-L54

Added lines #L51 - L54 were not covered by tests
)

val cpgQuerySarifBuilder = CPGQuerySarifBuilder(queries = queries, backend = backend)
return cpgQuerySarifBuilder.buildRun(findings = findings)

Check warning on line 58 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryExecutor.kt#L57-L58

Added lines #L57 - L58 were not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*

Check warning

Code scanning / detekt

Checks if top level class matches the filename Warning

File 'CPGQueryFinding.kt' contains a single class and possibly also extension functions for that class and should be named same after that class 'CpgQueryFinding.kt'
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native

import de.fraunhofer.aisec.codyze.backends.cpg.coko.getSarifLocation
import de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native.queries.CPGQuery
import de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.Finding
import de.fraunhofer.aisec.cpg.graph.Node
import io.github.detekt.sarif4k.Artifact
import io.github.detekt.sarif4k.Level
import io.github.detekt.sarif4k.Message
import io.github.detekt.sarif4k.Result
import java.nio.file.Path

/**
* An implementation of a [Finding] specifically for native queries.
*/
data class CpgQueryFinding(

Check warning

Code scanning / detekt

If a source file contains only a single non-private top-level class or object, the file name should reflect the case-sensitive name plus the .kt extension. Warning

The file name 'CPGQueryFinding' does not match the name of the single top-level declaration 'CpgQueryFinding'.
val message: String,
val kind: Finding.Kind = Finding.Kind.Fail,
val node: Node? = null,
val relatedNodes: Collection<Node>? = null,

Check warning on line 35 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt#L31-L35

Added lines #L31 - L35 were not covered by tests
) {
fun toSarif(query: CPGQuery, queries: List<CPGQuery>, artifacts: Map<Path, Artifact>?) =
Result(
message = Message(text = message),
kind = kind.resultKind,

Check warning on line 40 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt#L38-L40

Added lines #L38 - L40 were not covered by tests
level = if (kind == Finding.Kind.Fail) {
query.level

Check warning on line 42 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt#L42

Added line #L42 was not covered by tests
} else {
Level.None

Check warning on line 44 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt#L44

Added line #L44 was not covered by tests
},
ruleIndex = queries.indexOf(query).toLong(),

Check warning on line 46 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt#L46

Added line #L46 was not covered by tests
locations = node?.let { listOf(node.getSarifLocation(artifacts)) },
relatedLocations = relatedNodes?.map { node ->
node.getSarifLocation(artifacts)

Check warning on line 49 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryFinding.kt#L49

Added line #L49 was not covered by tests
}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native

import de.fraunhofer.aisec.codyze.core.executor.ExecutorOptions
import io.github.oshai.kotlinlogging.KotlinLogging

private val logger = KotlinLogging.logger {}

Check warning on line 21 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryOptionGroup.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryOptionGroup.kt#L21

Added line #L21 was not covered by tests

/**
* Contains all the options specific to the [CPGQueryExecutor]. For now this option group is an empty dummy.
*/
@Suppress("UNUSED")
class CPGQueryOptionGroup : ExecutorOptions("CPG Query Options")

Check warning on line 27 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryOptionGroup.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQueryOptionGroup.kt#L27

Added line #L27 was not covered by tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native

import de.fraunhofer.aisec.codyze.core.VersionProvider
import de.fraunhofer.aisec.codyze.core.backend.Backend
import de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native.queries.CPGQuery
import io.github.detekt.sarif4k.*

private fun CPGQuery.toReportingDescriptor() = ReportingDescriptor(
id = id,
name = javaClass.simpleName,
shortDescription = MultiformatMessageString(text = shortDescription),
fullDescription = MultiformatMessageString(text = description),
defaultConfiguration = ReportingConfiguration(level = level),
help = MultiformatMessageString(text = help),

Check warning on line 29 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt#L23-L29

Added lines #L23 - L29 were not covered by tests
properties =
PropertyBag(
tags = tags.toSet(),
map = emptyMap()

Check warning on line 33 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt#L31-L33

Added lines #L31 - L33 were not covered by tests
),
)

class CPGQuerySarifBuilder(val queries: List<CPGQuery>, val backend: Backend) {
val reportingDescriptors = queries.map { it.toReportingDescriptor() }
val toolComponent = ToolComponent(
name = "CPGQueryExecutor",
product = "Codyze",
organization = "Fraunhofer AISEC",
semanticVersion = VersionProvider.getVersion("cpg-queries"),
downloadURI = "https://github.com/Fraunhofer-AISEC/codyze/releases",
informationURI = "https://www.codyze.io",
rules = reportingDescriptors,

Check warning on line 46 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt#L37-L46

Added lines #L37 - L46 were not covered by tests
)

fun buildRun(findings: Map<CPGQuery, List<CpgQueryFinding>>): Run {
// build the SARIF run based on the received results
return Run(
tool = Tool(
driver = toolComponent,
extensions = listOf(backend.toolInfo)

Check warning on line 54 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt#L51-L54

Added lines #L51 - L54 were not covered by tests
),
artifacts = backend.artifacts.values.toList(),
results = findings.entries.flatMap { entry ->
entry.value.map { it.toSarif(entry.key, queries, backend.artifacts) }

Check warning on line 58 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySarifBuilder.kt#L56-L58

Added lines #L56 - L58 were not covered by tests
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved.

Check warning on line 2 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt#L2

Added line #L2 was not covered by tests
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native

import com.github.ajalt.clikt.parameters.groups.provideDelegate
import de.fraunhofer.aisec.codyze.backends.cpg.CPGBackend
import de.fraunhofer.aisec.codyze.core.backend.Backend
import de.fraunhofer.aisec.codyze.core.executor.ExecutorCommand

@Suppress("UNUSED")
class CPGQuerySubcommand : ExecutorCommand<CPGQueryExecutor>("runNativeQueries") {
val executorOptions by CPGQueryOptionGroup()

Check warning on line 25 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt#L24-L25

Added lines #L24 - L25 were not covered by tests

init {

Check warning on line 27 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt#L27

Added line #L27 was not covered by tests
// allow only the backends that implement the [CokoBackend] interface as subcommands
registerBackendOptions<CPGBackend>()

Check warning on line 29 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt#L29

Added line #L29 was not covered by tests
}

override fun getExecutor(goodFindings: Boolean, pedantic: Boolean, backend: Backend?) = with(executorOptions) {
CPGQueryExecutor(CPGQueryConfiguration(true), backend as CPGBackend)

Check warning on line 33 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/CPGQuerySubcommand.kt#L32-L33

Added lines #L32 - L33 were not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.fraunhofer.aisec.codyze.specificationLanguage.cpg.native

open abstract class Formatter {

Check warning

Code scanning / detekt

An abstract class is unnecessary. May be refactored to an interface or to a concrete class. Warning

An abstract class without a concrete member can be refactored to an interface.

Check warning on line 18 in codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/Formatter.kt

View check run for this annotation

Codecov / codecov/patch

codyze-specification-languages/cpg-native/src/main/kotlin/de/fraunhofer/aisec/codyze/specificationLanguage/cpg/native/Formatter.kt#L18

Added line #L18 was not covered by tests
public abstract fun format(k: String, v: String, attributes: Map<String, String>): String
}
Loading
Loading