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

chore: Major dependency updates #2977

Merged
merged 5 commits into from
Jan 9, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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 @@
// 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),

Check warning on line 35 in webapi/src/main/scala/dsp/valueobjects/User.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/dsp/valueobjects/User.scala#L35

Added line #L35 was not covered by tests
username => username.value
)

Expand Down Expand Up @@ -70,10 +69,7 @@
Username
.make(value)
.fold(
e => {
ZIO.logError(e.head.getMessage())
Validation.succeed(new Username(value) {})
},
_ => { Validation.succeed(new Username(value) {}) },

Check warning on line 72 in webapi/src/main/scala/dsp/valueobjects/User.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/dsp/valueobjects/User.scala#L72

Added line #L72 was not covered by tests
v => Validation.succeed(v)
)
}
Expand All @@ -86,7 +82,7 @@
// 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),

Check warning on line 85 in webapi/src/main/scala/dsp/valueobjects/User.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/dsp/valueobjects/User.scala#L85

Added line #L85 was not covered by tests
email => email.value
)

Expand All @@ -111,7 +107,7 @@
// 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),

Check warning on line 110 in webapi/src/main/scala/dsp/valueobjects/User.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/dsp/valueobjects/User.scala#L110

Added line #L110 was not covered by tests
givenName => givenName.value
)

Expand All @@ -131,7 +127,7 @@
// 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),

Check warning on line 130 in webapi/src/main/scala/dsp/valueobjects/User.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/dsp/valueobjects/User.scala#L130

Added line #L130 was not covered by tests
familyName => familyName.value
)

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

Expand All @@ -198,7 +193,7 @@
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 @@
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 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."
}
Original file line number Diff line number Diff line change
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