Skip to content

Commit

Permalink
fix: move files and add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
AnakinRaW authored and janniclas committed Sep 4, 2024
1 parent 48cf0b8 commit ad52333
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,25 @@ import org.koin.core.component.inject
import java.io.InputStream
import java.nio.file.FileSystem

data class TransformerOptions(
val tool : String,
val inputFiles : List<String>? = null
)

internal interface RawKpiTransformer {
fun getRawKpis(options: TransformerOptions, strictMode: Boolean) : Collection<RawValueKpi>
}

internal class Tool2RawKpiTransformer : RawKpiTransformer, KoinComponent{
internal class Tool2RawKpiTransformer : RawKpiTransformer, KoinComponent {

private val _fileSystem by inject<FileSystem>()
private val _logger = KotlinLogging.logger{}
private val _logger = KotlinLogging.logger {}

override fun getRawKpis(options: TransformerOptions, strictMode: Boolean): Collection<RawValueKpi> {

val result : Collection<AdapterResult> = when (options.tool) {
val result: Collection<AdapterResult> = when (options.tool) {
// "occmd" -> {
// val adapterInput: OccmdDto = OccmdAdapter.createInputFrom(input)
// OccmdAdapter.transformDataToKpi(adapterInput)
// }
"trivy" -> {
getSingleInputStreamFromInputFile(options.inputFiles, strictMode).use {
_logger.info { "Selected supported tool: Trivy" }
val adapterInput: TrivyDto = TrivyAdapter.dtoFromJson(it)
return@use TrivyAdapter.transformDataToKpi(adapterInput)
}
Expand All @@ -50,15 +46,15 @@ internal class Tool2RawKpiTransformer : RawKpiTransformer, KoinComponent{
}

// If we have unequal counts, we know that adapter returned faulted elements. Thus, we throw in strict mode.
if (strictMode && rawKpis.count() != result.count()){
if (strictMode && rawKpis.count() != result.count()) {
throw StrictModeConstraintFailed("The adapter produced faulted results.")
}

return rawKpis
}

internal fun getSingleInputStreamFromInputFile(inputFiles : List<String>?, strictMode : Boolean) : InputStream {
if (inputFiles.isNullOrEmpty()){
internal fun getSingleInputStreamFromInputFile(inputFiles: List<String>?, strictMode: Boolean): InputStream {
if (inputFiles.isNullOrEmpty()) {
throw IllegalStateException("No input files specified.")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.fraunhofer.iem.spha.cli.transformer

data class TransformerOptions(
val tool : String,
val inputFiles : List<String>? = null
)

0 comments on commit ad52333

Please sign in to comment.