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

Play 3.0 upgrade #546

Merged
merged 2 commits into from
Jan 7, 2025
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
4 changes: 2 additions & 2 deletions app/controllers/ReadOnlyApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ReadOnlyApi(
val xmlTags = tags.get.sortBy(_.id).map(_.asExportedXml(sections))

Ok(<tags>
{xmlTags.seq.map { x => x }}
{xmlTags.map { x => x }}
</tags>)
}

Expand All @@ -48,7 +48,7 @@ class ReadOnlyApi(


Ok(<sections>
{xmlSections.seq.map { x => x }}
{xmlSections.map { x => x }}
</sections>)
}

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/Support.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import services.{AWS, Config, FetchError, ImageMetadataService, InvalidImage}

import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal
import collection.JavaConverters._
import scala.jdk.CollectionConverters._

class Support(
val wsClient: WSClient,
Expand Down
2 changes: 1 addition & 1 deletion app/model/command/RemoveEditionFromSectionCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ case class RemoveEditionFromSectionCommand(sectionId: Long, editionName: String)

val pageId = try { PathManager.removePathForId(editionInfo.pageId) } catch { case p: PathRemoveFailed => PathNotFound}

val updatedEditions = section.editions.filterKeys(_.toUpperCase != editionName.toUpperCase).toMap
val updatedEditions = section.editions.view.filterKeys(_.toUpperCase != editionName.toUpperCase).toMap

val updatedSection = section.copy(
editions = updatedEditions,
Expand Down
2 changes: 1 addition & 1 deletion app/repositories/ContentAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object ContentAPI extends Logging {

def countOccurencesOfTagInContents(contentIds: List[String], apiTagId: String)(implicit ec: ExecutionContext): Int = {
if (contentIds.nonEmpty) {
val builder = StringBuilder.newBuilder
val builder = new StringBuilder()
var pageSize = 0

var total = 0
Expand Down
58 changes: 41 additions & 17 deletions app/services/AWS.scala
Original file line number Diff line number Diff line change
@@ -1,36 +1,54 @@
package services

import java.nio.ByteBuffer

import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.regions.{Region, Regions}
import com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClient
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient
import com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClientBuilder
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder
import com.amazonaws.services.dynamodbv2.document.DynamoDB
import com.amazonaws.services.ec2.AmazonEC2Client
import com.amazonaws.services.ec2.AmazonEC2ClientBuilder
import com.amazonaws.services.ec2.model.{DescribeTagsRequest, Filter}
import com.amazonaws.services.kinesis.AmazonKinesisClient
import com.amazonaws.services.s3.AmazonS3Client
import com.amazonaws.services.sqs.AmazonSQSClient
import com.amazonaws.services.kinesis.AmazonKinesisClientBuilder
import com.amazonaws.services.s3.{AmazonS3Client, AmazonS3ClientBuilder}
import com.amazonaws.services.sqs.AmazonSQSClientBuilder
import com.amazonaws.util.EC2MetadataUtils
import com.twitter.scrooge.ThriftStruct
import play.api.Logging
import services.AWS.region

import scala.jdk.CollectionConverters._

object AWS {

lazy val region = Region getRegion Regions.EU_WEST_1

lazy val EC2Client = region.createClient(classOf[AmazonEC2Client], null, null)
lazy val CloudWatch = region.createClient(classOf[AmazonCloudWatchAsyncClient], null, null)
lazy val Kinesis = region.createClient(classOf[AmazonKinesisClient], null, null)
lazy val S3Client = region.createClient(classOf[AmazonS3Client], null, null)

private lazy val frontendCredentialsProvider = Config().frontendBucketWriteRole.map(new STSAssumeRoleSessionCredentialsProvider(_, "tagManager"))

lazy val frontendStaticFilesS3Client = region.createClient(classOf[AmazonS3Client], frontendCredentialsProvider.getOrElse(new ProfileCredentialsProvider("frontend")), null)
lazy val EC2Client = AmazonEC2ClientBuilder
.standard()
.withRegion(region.getName)
.build()
lazy val CloudWatch = AmazonCloudWatchAsyncClientBuilder
.standard()
.withRegion(region.getName)
.build()
lazy val Kinesis = AmazonKinesisClientBuilder
.standard()
.withRegion(region.getName)
.build()
lazy val S3Client = AmazonS3ClientBuilder
.standard()
.withRegion(region.getName)
.build()

private lazy val frontendCredentialsProvider = Config().frontendBucketWriteRole.map(
new STSAssumeRoleSessionCredentialsProvider.Builder(_, "tagManager").build()
)

lazy val frontendStaticFilesS3Client = AmazonS3ClientBuilder
.standard()
.withCredentials(frontendCredentialsProvider.getOrElse(new ProfileCredentialsProvider("frontend")))
.withRegion(region.getName)
.build()
}

trait AwsInstanceTags {
Expand All @@ -51,7 +69,10 @@ trait AwsInstanceTags {
}

object Dynamo {
lazy val client = AWS.region.createClient(classOf[AmazonDynamoDBClient], null, null)
lazy val client = AmazonDynamoDBClientBuilder
.standard()
.withRegion(AWS.region.getName)
.build()
lazy val dynamoDb = new DynamoDB(client)

lazy val tagTable = dynamoDb.getTable(Config().tagsTableName)
Expand All @@ -72,7 +93,10 @@ object Dynamo {
}

object SQS {
lazy val SQSClient = AWS.region.createClient(classOf[AmazonSQSClient], null, null)
lazy val SQSClient = AmazonSQSClientBuilder
.standard()
.withRegion(region.getName)
.build()

lazy val jobQueue = new SQSQueue(Config().jobQueueName)
}
Expand Down
2 changes: 1 addition & 1 deletion app/services/SQSQueue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.util.concurrent.atomic.AtomicBoolean

import com.amazonaws.services.sqs.model._
import play.api.Logging
import collection.JavaConverters._
import scala.jdk.CollectionConverters._
import scala.annotation.tailrec
import scala.util.control.NonFatal

Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ lazy val dependencies = Seq(
"com.amazonaws" % "aws-java-sdk-sqs" % awsVersion,
"com.amazonaws" % "aws-java-sdk-sts" % awsVersion,
"com.amazonaws" % "amazon-kinesis-client" % "1.14.10",
"com.gu" %% "pan-domain-auth-play_2-8" % pandaVersion,
"com.gu" %% "pan-domain-auth-play_3-0" % pandaVersion,
"com.gu" %% "editorial-permissions-client" % "2.15",
ws, // for panda
"ai.x" %% "play-json-extensions" % "0.42.0",
Expand All @@ -39,7 +39,7 @@ lazy val dependencies = Seq(
"net.logstash.logback" % "logstash-logback-encoder" % "7.2",
"org.slf4j" % "slf4j-api" % "1.7.12",
"org.slf4j" % "jcl-over-slf4j" % "1.7.12",
"com.gu" %% "panda-hmac-play_2-8" % pandaVersion,
"com.gu" %% "panda-hmac-play_3-0" % pandaVersion,
"com.gu" %% "content-api-client-aws" % "0.7.4",
"com.beachape" %% "enumeratum" % "1.5.13",
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
Expand Down
4 changes: 3 additions & 1 deletion conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ play.application.loader = AppLoader
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
play.http.secret.key=everybodylovestags
#
# If a Play app needs a secure Play Application Secret, it should use https://github.com/guardian/play-secret-rotation
play.http.secret.key="This app doesn't need a secure PAS so long as it DOES NOT use session cookies, CSRF tokens, etc"

# The application languages
# ~~~~~
Expand Down
8 changes: 3 additions & 5 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.19")
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.5")

addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.4.4")
addSbtPlugin("com.github.sbt" % "sbt-digest" % "2.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.3")

addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.2")
addSbtPlugin("com.github.sbt" % "sbt-gzip" % "2.0.0")

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.12.0")

Expand Down
Loading