-
Notifications
You must be signed in to change notification settings - Fork 559
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable ETag-caching on Facia API requests
With guardian/facia-scala-client#287, the Facia client has been updated so that it can take advantage of ETag-caching, using the https://github.com/guardian/etag-caching library already used in Frontend since August 2023 with #26338. As some changes were necessary in the `etag-caching` library to facilitate this, we need to update the version of `etag-caching` used by Frontend to v7.0.0. We're also upgrading the S3 client (used by Frontend's instance of Facia's `ApiClient`) to AWS SDK v2, as `etag-caching` already provides a convenient implementation of `S3ByteArrayFetching` (see guardian/etag-caching#65) for AWS SDK v2 - if we continued using AWS SDK v1 here in Frontend, we'd have to create an implementation for it. ## See also * guardian/maintaining-scala-projects#9 * guardian/facia-scala-client#287
- Loading branch information
Showing
5 changed files
with
53 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
package services.fronts | ||
|
||
import com.amazonaws.services.s3.{AmazonS3, AmazonS3Client} | ||
import com.gu.facia.client.{AmazonSdkS3Client, ApiClient} | ||
import com.gu.etagcaching.aws.sdkv2.s3.S3ObjectFetching | ||
import com.gu.facia.client.{ApiClient, Environment} | ||
import conf.Configuration | ||
import utils.AWSv2.buildS3AsyncClient | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
object FrontsApi { | ||
|
||
def crossAccountClient(implicit ec: ExecutionContext): ApiClient = { | ||
val client: AmazonS3 = AmazonS3Client.builder | ||
.withCredentials(Configuration.faciatool.crossAccountMandatoryCredentials) | ||
.withRegion(conf.Configuration.aws.region) | ||
.build() | ||
ApiClient( | ||
Configuration.faciatool.crossAccountSourceBucket, | ||
Configuration.facia.stage.toUpperCase, | ||
AmazonSdkS3Client(client), | ||
) | ||
} | ||
def crossAccountClient(implicit ec: ExecutionContext): ApiClient = ApiClient.withCaching( | ||
Configuration.faciatool.crossAccountSourceBucket, | ||
Environment(Configuration.facia.stage.toUpperCase), | ||
S3ObjectFetching.byteArraysWith(buildS3AsyncClient(Configuration.faciatool.crossAccountMandatoryCredentials)), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters