Skip to content

Commit

Permalink
feat(guard): add matching and masking functions, remove Joni dependency
Browse files Browse the repository at this point in the history
#47

Adds the ability to match and mask secret patterns in the `SecretPatterns` class. Removes the Joni regex library dependency and replaces it with Kotlin's native regex support.
  • Loading branch information
phodal committed Aug 2, 2024
1 parent bcc7e16 commit 6a12233
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,12 @@ project(":core") {
dependencies {
// Java port of Oniguruma regexp library
// for Share regex pattern in different languages
implementation("org.jruby.joni:joni:2.2.1")
// implementation("org.jruby.joni:joni:2.2.1")

implementation("com.charleskorn.kaml:kaml:0.61.0")
implementation("org.reflections:reflections:0.10.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")


// chocolate factory
// follow: https://onnxruntime.ai/docs/get-started/with-java.html
implementation("com.microsoft.onnxruntime:onnxruntime:1.18.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.phodal.shirecore.guard.model
import com.intellij.openapi.diagnostic.logger
import kotlinx.serialization.Contextual
import kotlinx.serialization.Serializable
import org.joni.Regex;

@Serializable
data class SecretPatterns(
Expand All @@ -28,4 +27,12 @@ class SecretPatternDetail(
logger<SecretPatternDetail>().error("Invalid regex pattern: $regex, name: $name")
null
}

fun matches(text: String): Boolean {
return regexPattern?.containsMatchIn(text) ?: false
}

fun mask(text: String): String {
return regexPattern?.replace(text, "****") ?: text
}
}

0 comments on commit 6a12233

Please sign in to comment.