Skip to content

Commit

Permalink
Feat/scala steward upgrades 5 (#72)
Browse files Browse the repository at this point in the history
* Update xz to 1.10

* Update s3, sts to 2.26.29

* Use RetryStrategy instead of RetryPolicy

---------

Co-authored-by: Scala Steward <[email protected]>
  • Loading branch information
davidsloan and scala-steward authored Aug 9, 2024
1 parent 8513235 commit e902f7f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import software.amazon.awssdk.auth.credentials.AwsCredentials
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration
import software.amazon.awssdk.core.retry.RetryPolicy
import software.amazon.awssdk.core.retry.backoff.FixedDelayBackoffStrategy
import software.amazon.awssdk.http.apache.ApacheHttpClient
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.retries.api.RetryStrategy
import software.amazon.awssdk.retries.api.internal.backoff.FixedDelayWithoutJitter
import software.amazon.awssdk.services.s3.S3Client
import software.amazon.awssdk.services.s3.S3Configuration

Expand All @@ -45,18 +45,6 @@ object AwsS3ClientCreator extends ClientCreator[S3ConnectionConfig, S3Client] {

def make(config: S3ConnectionConfig): Either[Throwable, S3Client] =
for {
retryPolicy <- Try {
RetryPolicy
.builder()
.numRetries(config.httpRetryConfig.getRetryLimit)
.backoffStrategy(
FixedDelayBackoffStrategy.create(Duration.ofMillis(config.httpRetryConfig.getRetryIntervalMillis)),
)
.build()
}.toEither

overrideConfig <- Try(ClientOverrideConfiguration.builder().retryPolicy(retryPolicy).build()).toEither

s3Config <- Try {
S3Configuration
.builder
Expand All @@ -71,27 +59,61 @@ object AwsS3ClientCreator extends ClientCreator[S3ConnectionConfig, S3Client] {
config.connectionPoolConfig.foreach(t => apacheHttpClientBuilder.maxConnections(t.maxConnections))
apacheHttpClientBuilder.build()
}.toEither
s3Client <- credentialsProvider(config).leftMap(new IllegalArgumentException(_)).flatMap { credsProv =>
Try(
S3Client
.builder()
.overrideConfiguration(overrideConfig)
.serviceConfiguration(s3Config)
.credentialsProvider(credsProv)
.httpClient(httpClient),
).toEither
s3Client <- credentialsProvider(config)
.leftMap(new IllegalArgumentException(_))
.flatMap {
credsProv =>
Try(
S3Client
.builder()
.overrideConfiguration((clientOverrideConfigurationBuilder: ClientOverrideConfiguration.Builder) =>
customiseOverrideConfiguration(config, clientOverrideConfigurationBuilder),
)
.serviceConfiguration(s3Config)
.credentialsProvider(credsProv)
.httpClient(httpClient),
).toEither

}.map { builder =>
config
.region
.fold(builder)(reg => builder.region(Region.of(reg)))
}.map { builder =>
config.customEndpoint.fold(builder)(cE => builder.endpointOverride(URI.create(cE)))
}.flatMap { builder =>
Try(builder.build()).toEither
}
}.map { builder =>
config
.region
.fold(builder)(reg => builder.region(Region.of(reg)))
}.map { builder =>
config.customEndpoint.fold(builder)(cE => builder.endpointOverride(URI.create(cE)))
}.flatMap { builder =>
Try(builder.build()).toEither
}
} yield s3Client

private def customiseOverrideConfiguration(
config: S3ConnectionConfig,
clientOverrideConfigurationBuilder: ClientOverrideConfiguration.Builder,
): Unit = {
clientOverrideConfigurationBuilder
.retryStrategy { (retryStrategyBuilder: RetryStrategy.Builder[_, _]) =>
customiseRetryStrategy(config, retryStrategyBuilder)
}
()
}

private def customiseRetryStrategy(
config: S3ConnectionConfig,
retryStrategyBuilder: RetryStrategy.Builder[_, _],
): Unit = {
retryStrategyBuilder
.maxAttempts(config.httpRetryConfig.getRetryLimit)

retryStrategyBuilder.backoffStrategy(
new FixedDelayWithoutJitter(
Duration.ofMillis(
config.httpRetryConfig.getRetryIntervalMillis,
),
),
)

()
}

private def credentialsFromConfig(awsConfig: S3ConnectionConfig): Either[String, AwsCredentialsProvider] =
awsConfig.accessKey.zip(awsConfig.secretKey) match {
case Some((access, secret)) =>
Expand Down
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ object Dependencies {
val jerseyCommonVersion = "3.1.8"

val calciteVersion = "1.34.0"
val awsSdkVersion = "2.25.70"
val awsSdkVersion = "2.26.29"

val azureDataLakeVersion = "12.20.0"
val azureIdentityVersion = "1.13.2"
Expand All @@ -95,7 +95,7 @@ object Dependencies {
val openCsvVersion = "5.9"
val jsonSmartVersion = "2.5.1"

val xzVersion = "1.9"
val xzVersion = "1.10"
val lz4Version = "1.8.0"

val bouncyCastleVersion = "1.78.1"
Expand Down

0 comments on commit e902f7f

Please sign in to comment.