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

Fix file encoding selection #68

Merged
merged 1 commit into from
Oct 31, 2023
Merged
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 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
Loading