Skip to content

Commit

Permalink
Fix file encoding selection (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsloan authored Oct 31, 2023
1 parent ab8408e commit b9b4eee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ object Settings extends Dependencies {
targetDir.mkdirs()

val propertiesFileChanged = createPomPropertiesIfChanged(groupId, artifactId, version, targetDir)
if(propertiesFileChanged) {
if (propertiesFileChanged) {
createPomXml(log, targetDir, pomUrl)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ import com.azure.core.credential.TokenCredential
import com.azure.identity.ClientSecretCredentialBuilder
import com.azure.identity.DefaultAzureCredentialBuilder
import com.azure.security.keyvault.secrets.SecretClient
import com.azure.security.keyvault.secrets.models.SecretProperties
import com.typesafe.scalalogging.StrictLogging
import io.lenses.connect.secrets.config.AzureProviderSettings
import io.lenses.connect.secrets.connect
import io.lenses.connect.secrets.connect.Encoding.Encoding
import io.lenses.connect.secrets.connect._
import org.apache.kafka.connect.errors.ConnectException

import java.nio.file.FileSystems
import java.time.OffsetDateTime
import scala.jdk.CollectionConverters.MapHasAsScala
import scala.util.Failure
import scala.util.Success
import scala.util.Try
Expand All @@ -37,16 +41,7 @@ trait AzureHelper extends StrictLogging {
val value = secret.getValue
val props = secret.getProperties

// check the file-encoding
val encoding =
Encoding.withoutHyphensInsensitiveOpt(
Option(props.getTags)
.map(_.getOrDefault(FILE_ENCODING, Encoding.UTF8.toString))
.getOrElse(Encoding.UTF8.toString)
.toUpperCase,
)

val content = encoding match {
val content = retrieveEncodingFromTags(props) match {
case Encoding.UTF8 =>
value

Expand Down Expand Up @@ -86,6 +81,16 @@ trait AzureHelper extends StrictLogging {
)
}

private def retrieveEncodingFromTags(props: SecretProperties): connect.Encoding.Value =
// check the file-encoding
{
for {
propsMap <- Option(props.getTags.asScala)
fileEncodingFromPropsMap <- propsMap.get(FILE_ENCODING)
enc <- Encoding.withoutHyphensInsensitiveOpt(fileEncodingFromPropsMap)
} yield enc
}.getOrElse(Encoding.UTF8)

// setup azure credentials
def createCredentials(settings: AzureProviderSettings): TokenCredential = {

Expand Down

0 comments on commit b9b4eee

Please sign in to comment.