Skip to content

Commit

Permalink
chore: Major dependency updates (#2977)
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Kleinbölting <christian.kleinboelting@dasch.swiss>
Co-authored-by: Christian Kleinbölting <seakayone@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 9, 2024
1 parent 700f3c5 commit 6ee0111
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 40 deletions.
Expand Up @@ -8,8 +8,7 @@ package org.knora.webapi.config
import com.typesafe.config.ConfigFactory
import zio._
import zio.config._
import zio.config.magnolia._
import zio.config.typesafe.TypesafeConfigSource
import zio.config.typesafe.TypesafeConfigProvider

import org.knora.webapi.config.AppConfig.AppConfigurations
import org.knora.webapi.testcontainers.DspIngestTestContainer
Expand Down Expand Up @@ -66,16 +65,16 @@ object AppConfigForTestContainers {
}

/**
* Reads in the applicaton configuration using ZIO-Config. ZIO-Config is capable of loading
* Reads in the application configuration using ZIO-Config. ZIO-Config is capable of loading
* the Typesafe-Config format. Reads the 'app' configuration from 'application.conf'.
*/
private val source: ConfigSource =
TypesafeConfigSource.fromTypesafeConfig(ZIO.attempt(ConfigFactory.load().getConfig("app").resolve))
private val source: ConfigProvider =
TypesafeConfigProvider.fromTypesafeConfig(ConfigFactory.load().getConfig("app").resolve)

/**
* Intantiates our config class hierarchy using the data from the 'app' configuration from 'application.conf'.
* Instantiates our config class hierarchy using the data from the 'app' configuration from 'application.conf'.
*/
private val config: UIO[AppConfig] = (read(descriptor[AppConfig].mapKey(toKebabCase) from source)).orDie
private val config: UIO[AppConfig] = read(AppConfig.descriptor from source).orDie

/**
* Altered AppConfig with ports from TestContainers for DSP-Ingest, Fuseki and Sipi.
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Expand Up @@ -21,7 +21,7 @@ object Dependencies {
val PekkoHttpVersion = "1.0.0"
val JenaVersion = "4.10.0"

val ZioConfigVersion = "3.0.7"
val ZioConfigVersion = "4.0.0"
val ZioLoggingVersion = "2.1.16"
val ZioNioVersion = "2.0.2"
val ZioMetricsConnectorsVersion = "2.3.1"
Expand Down
44 changes: 14 additions & 30 deletions webapi/src/main/scala/dsp/valueobjects/User.scala
Expand Up @@ -8,7 +8,6 @@ package dsp.valueobjects
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder
import zio.*
import zio.config.magnolia.Descriptor
import zio.json.JsonCodec
import zio.json.JsonDecoder
import zio.json.JsonEncoder
Expand All @@ -33,7 +32,7 @@ object User {
// the codec defines how to decode/encode the object from/into json
implicit val codec: JsonCodec[Username] =
JsonCodec[String].transformOrFail(
value => Username.make(value).toEitherWith(e => e.head.getMessage()),
value => Username.make(value).toEitherWith(e => e.head.getMessage),
username => username.value
)

Expand Down Expand Up @@ -70,10 +69,7 @@ object User {
Username
.make(value)
.fold(
e => {
ZIO.logError(e.head.getMessage())
Validation.succeed(new Username(value) {})
},
_ => { Validation.succeed(new Username(value) {}) },
v => Validation.succeed(v)
)
}
Expand All @@ -86,7 +82,7 @@ object User {
// the codec defines how to decode/encode the object from/into json
implicit val codec: JsonCodec[Email] =
JsonCodec[String].transformOrFail(
value => Email.make(value).toEitherWith(e => e.head.getMessage()),
value => Email.make(value).toEitherWith(e => e.head.getMessage),
email => email.value
)

Expand All @@ -111,7 +107,7 @@ object User {
// the codec defines how to decode/encode the object from/into json
implicit val codec: JsonCodec[GivenName] =
JsonCodec[String].transformOrFail(
value => GivenName.make(value).toEitherWith(e => e.head.getMessage()),
value => GivenName.make(value).toEitherWith(e => e.head.getMessage),
givenName => givenName.value
)

Expand All @@ -131,7 +127,7 @@ object User {
// the codec defines how to decode/encode the object from/into json
implicit val codec: JsonCodec[FamilyName] =
JsonCodec[String].transformOrFail(
value => FamilyName.make(value).toEitherWith(e => e.head.getMessage()),
value => FamilyName.make(value).toEitherWith(e => e.head.getMessage),
familyName => familyName.value
)

Expand Down Expand Up @@ -184,7 +180,6 @@ object User {
val encoder = new BCryptPasswordEncoder()
encoder.matches(passwordString, self.value)
} else {
ZIO.logError(UserErrorMessages.PasswordHashUnknown)
false
}

Expand All @@ -198,7 +193,7 @@ object User {
val passwordStrength =
PasswordStrength.make(passwordStrengthInt).fold(e => throw new ValidationException(e.head), v => v)

PasswordHash.make(password, passwordStrength).toEitherWith(e => e.head.getMessage())
PasswordHash.make(password, passwordStrength).toEitherWith(e => e.head.getMessage)
}
// the encoder defines how to encode the object into json
implicit val encoder: JsonEncoder[PasswordHash] =
Expand Down Expand Up @@ -236,13 +231,6 @@ object User {
passwordStrength => passwordStrength
)

// this is used for the configuration descriptor
implicit val descriptorForPasswordStrength: Descriptor[PasswordStrength] =
Descriptor[Int].transformOrFail(
int => PasswordStrength.make(int).toEitherWith(_.toString()),
r => Right(r.toInt)
)

override def assertion = assert {
greaterThanOrEqualTo(4) &&
lessThanOrEqualTo(31)
Expand Down Expand Up @@ -288,16 +276,12 @@ object User {
}

object UserErrorMessages {
val UsernameMissing = "Username cannot be empty."
val UsernameInvalid = "Username is invalid."
val EmailMissing = "Email cannot be empty."
val EmailInvalid = "Email is invalid."
val PasswordMissing = "Password cannot be empty."
val PasswordInvalid = "Password is invalid."
val PasswordStrengthInvalid = "PasswordStrength is invalid."
val PasswordHashUnknown = "The provided PasswordHash has an unknown format."
val GivenNameMissing = "GivenName cannot be empty."
val GivenNameInvalid = "GivenName is invalid."
val FamilyNameMissing = "FamilyName cannot be empty."
val FamilyNameInvalid = "FamilyName is invalid."
val UsernameMissing = "Username cannot be empty."
val UsernameInvalid = "Username is invalid."
val EmailMissing = "Email cannot be empty."
val EmailInvalid = "Email is invalid."
val PasswordMissing = "Password cannot be empty."
val PasswordInvalid = "Password is invalid."
val GivenNameMissing = "GivenName cannot be empty."
val FamilyNameMissing = "FamilyName cannot be empty."
}
6 changes: 4 additions & 2 deletions webapi/src/main/scala/org/knora/webapi/config/AppConfig.scala
Expand Up @@ -205,10 +205,12 @@ final case class InstrumentationServerConfig(
object AppConfig {
type AppConfigurations = AppConfig & JwtConfig & DspIngestConfig & Triplestore

val descriptor: Config[AppConfig] = deriveConfig[AppConfig].mapKey(toKebabCase)

val layer: ULayer[AppConfigurations] = {
val appConfigLayer = ZLayer {
val source = TypesafeConfigSource.fromTypesafeConfig(ZIO.attempt(ConfigFactory.load().getConfig("app").resolve))
read(descriptor[AppConfig].mapKey(toKebabCase) from source).orDie
val source = TypesafeConfigProvider.fromTypesafeConfig(ConfigFactory.load().getConfig("app").resolve)
read(descriptor from source).orDie
}
projectAppConfigurations(appConfigLayer).tap(_ => ZIO.logInfo(">>> AppConfig Initialized <<<"))
}
Expand Down

0 comments on commit 6ee0111

Please sign in to comment.