Skip to content

Commit

Permalink
Merge branch 't2062-special-chars' of github.com:bbc/grid into t2062-…
Browse files Browse the repository at this point in the history
…special-chars
  • Loading branch information
AndyKilmory committed Jan 9, 2025
2 parents 17a0805 + a01da44 commit da4e5a1
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 39 deletions.
1 change: 0 additions & 1 deletion auth/app/auth/AuthConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ import com.gu.mediaservice.lib.config.{CommonConfig, GridConfigResources}
class AuthConfig(resources: GridConfigResources) extends CommonConfig(resources) {
val rootUri: String = services.authBaseUri
val mediaApiUri: String = services.apiBaseUri
val kahunaUri = services.kahunaBaseUri
}
12 changes: 6 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ lazy val cropper = playProject("cropper", 9006)

lazy val imageLoader = playProject("image-loader", 9003).settings {
libraryDependencies ++= Seq(
"org.apache.tika" % "tika-core" % "1.20",
"com.drewnoakes" % "metadata-extractor" % "2.17.0"
"org.apache.tika" % "tika-core" % "1.28.5",
"com.drewnoakes" % "metadata-extractor" % "2.19.0"
)
}

Expand Down Expand Up @@ -158,14 +158,14 @@ lazy val thrall = playProject("thrall", 9002)
pipelineStages := Seq(digest, gzip),
libraryDependencies ++= Seq(
"org.codehaus.groovy" % "groovy-json" % "3.0.7",
"software.amazon.kinesis" % "amazon-kinesis-client" % "2.4.2",
// TODO upgrading kcl to v3? check if you can remove avro override below
"software.amazon.kinesis" % "amazon-kinesis-client" % "2.6.0",
"io.github.streetcontxt" %% "kcl-akka-stream" % "4.1.1",
"org.testcontainers" % "elasticsearch" % "1.19.2" % Test,
"com.google.protobuf" % "protobuf-java" % "3.19.6"
),
// amazon-kinesis-client 2.4.2 brings in a critically vulnerable version of apache avro,
// but we cannot upgrade amazon-kinesis-client further until we move into slf4j v2.
// TODO when upgrading kinesis-client - can we remove this override?
// amazon-kinesis-client 2.6.0 brings in a critically vulnerable version of apache avro,
// but we cannot upgrade amazon-kinesis-client further without performing the v2->v3 upgrade https://docs.aws.amazon.com/streams/latest/dev/kcl-migration-from-2-3.html
dependencyOverrides += "org.apache.avro" % "avro" % "1.11.4"
)

Expand Down
2 changes: 0 additions & 2 deletions collections/app/lib/CollectionsConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ class CollectionsConfig(resources: GridConfigResources) extends CommonConfig(res
val imageCollectionsTable = string("dynamo.table.imageCollections")

val rootUri = services.collectionsBaseUri
val kahunaUri = services.kahunaBaseUri
val loginUriTemplate = services.loginUriTemplate
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ abstract class CommonConfig(resources: GridConfigResources) extends AwsClientV1B
val maybeIngestBucket: Option[String] = stringOpt("s3.ingest.bucket")
val maybeFailBucket: Option[String] = stringOpt("s3.fail.bucket")

val maybeUploadLimitInBytes: Option[Int] = intOpt("upload.limit.mb").map(_ * 1_000_000)

// Note: had to make these lazy to avoid init order problems ;_;
val domainRoot: String = string("domain.root")
val domainRootOverride: Option[String] = stringOpt("domain.root-override")
Expand Down
2 changes: 1 addition & 1 deletion cropper/app/lib/CropStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CropStore(config: CropperConfig) extends S3ImageStorage(config) with CropS
crops.foldLeft(Map[String, Crop]()) {
case (map, (s3Object)) => {
val filename::containingFolder::_ = s3Object.uri.getPath.split("/").reverse.toList
var isMaster = containingFolder == "master"
val isMaster = containingFolder == "master"
val userMetadata = s3Object.metadata.userMetadata
val objectMetadata = s3Object.metadata.objectMetadata

Expand Down
2 changes: 0 additions & 2 deletions cropper/app/lib/CropperConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class CropperConfig(resources: GridConfigResources) extends CommonConfig(resourc

val rootUri = services.cropperBaseUri
val apiUri = services.apiBaseUri
val kahunaUri = services.kahunaBaseUri
val loginUriTemplate = services.loginUriTemplate

val tempDir: File = new File(stringDefault("crop.output.tmp.dir", "/tmp"))

Expand Down
14 changes: 13 additions & 1 deletion image-loader/app/controllers/ImageLoaderController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,19 @@ class ImageLoaderController(auth: Authentication,

val approximateReceiveCount = getApproximateReceiveCount(sqsMessage)

if (approximateReceiveCount > 2) {
if(config.maybeUploadLimitInBytes.exists(_ < s3IngestObject.contentLength)){
val errorMessage = s"File size exceeds the maximum allowed size (${config.maybeUploadLimitInBytes.get / 1_000_000}MB). Moving to fail bucket."
logger.warn(logMarker, errorMessage)
store.moveObjectToFailedBucket(s3IngestObject.key)
s3IngestObject.maybeMediaIdFromUiUpload foreach { imageId =>
uploadStatusTable.updateStatus( // fire & forget, since there's nothing else we can do
imageId, UploadStatus(StatusType.Failed, Some(errorMessage))
)
}
metrics.failedIngestsFromQueue.incrementBothWithAndWithoutDimensions(metricDimensions)
Future.unit
}
else if (approximateReceiveCount > 2) {
metrics.abandonedMessagesFromQueue.incrementBothWithAndWithoutDimensions(metricDimensions)
val errorMessage = s"File processing has been attempted $approximateReceiveCount times. Moving to fail bucket."
logger.warn(logMarker, errorMessage)
Expand Down
1 change: 1 addition & 0 deletions kahuna/app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
permissionsDefault: "@kahunaConfig.permissionsDefault",
defaultShouldBlurGraphicImages: @kahunaConfig.defaultShouldBlurGraphicImages,
shouldUploadStraightToBucket: @kahunaConfig.shouldUploadStraightToBucket,
maybeUploadLimitInBytes: @kahunaConfig.maybeUploadLimitInBytes,
announcements: @Html(announcements),
imageTypes: @Html(imageTypes),
}
Expand Down
16 changes: 15 additions & 1 deletion kahuna/public/js/upload/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,21 @@ upload.factory('uploadManager',
};
}

async function createJobItems(files){
async function createJobItems(_files){

const maybeUploadLimitInBytes = window._clientConfig.maybeUploadLimitInBytes;
const maybeFilesAboveSizeLimit = !!maybeUploadLimitInBytes && _files.filter(file => file.size > maybeUploadLimitInBytes);

if (maybeFilesAboveSizeLimit && maybeFilesAboveSizeLimit.length > 0){
alert(`The following files will be skipped as they are above the size limit of ${maybeUploadLimitInBytes / 1_000_000}MB:\n${
maybeFilesAboveSizeLimit.map(file => file.name).join("\n")
}`);
}

const files = maybeFilesAboveSizeLimit && maybeFilesAboveSizeLimit.length > 0
? _files.filter(file => !maybeFilesAboveSizeLimit.includes(file))
: _files;

if (window._clientConfig.shouldUploadStraightToBucket) {
const mediaIdToFileMap = Object.fromEntries(
await Promise.all(
Expand Down
2 changes: 0 additions & 2 deletions leases/app/lib/LeasesConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class LeasesConfig(resources: GridConfigResources) extends CommonConfig(resource
val leasesTable = string("dynamo.tablename.leasesTable")

val rootUri: String = services.leasesBaseUri
val kahunaUri: String = services.kahunaBaseUri
val loginUriTemplate: String = services.loginUriTemplate

private def uri(u: String) = URI.create(u)

Expand Down
3 changes: 0 additions & 3 deletions media-api/app/MediaApiComponents.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import com.gu.mediaservice.lib.aws.ThrallMessageSender
import com.gu.mediaservice.lib.imaging.ImageOperations
import com.gu.mediaservice.lib.management.{ElasticSearchHealthCheck, InnerServiceStatusCheckController, Management}
import com.gu.mediaservice.lib.metadata.SoftDeletedMetadataTable
import com.gu.mediaservice.lib.play.GridComponents
Expand All @@ -14,8 +13,6 @@ import scala.concurrent.Future
class MediaApiComponents(context: Context) extends GridComponents(context, new MediaApiConfig(_)) {
final override val buildInfo = utils.buildinfo.BuildInfo

val imageOperations = new ImageOperations(context.environment.rootPath.getAbsolutePath)

val messageSender = new ThrallMessageSender(config.thrallKinesisStreamConfig)
val mediaApiMetrics = new MediaApiMetrics(config, actorSystem, applicationLifecycle)

Expand Down
4 changes: 0 additions & 4 deletions media-api/app/lib/ImageResponse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,6 @@ class ImageResponse(config: MediaApiConfig, s3Client: S3Client, usageQuota: Usag
def makeImgopsUri(uri: URI): String =
config.imgopsUri + List(uri.getPath, uri.getRawQuery).mkString("?") + "{&w,h,q}"

def makeOptimisedPngImageopsUri(uri: URI): String = {
config.imgopsUri + List(uri.getPath, uri.getRawQuery).mkString("?") + "{&w, h, q}"
}

private def updateCustomSpecialInstructions(source: JsValue): Reads[JsObject] = {
(source \ "usageRights" \ "category") match {
case JsDefined(category) =>
Expand Down
2 changes: 0 additions & 2 deletions media-api/app/lib/MediaApiConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ class MediaApiConfig(resources: GridConfigResources) extends CommonConfigWithEla
val kahunaUri: String = services.kahunaBaseUri
val cropperUri: String = services.cropperBaseUri
val loaderUri: String = services.loaderBaseUri
val projectionUri: String = services.projectionBaseUri
val metadataUri: String = services.metadataBaseUri
val imgopsUri: String = services.imgopsBaseUri
val usageUri: String = services.usageBaseUri
val leasesUri: String = services.leasesBaseUri
val authUri: String = services.authBaseUri
val loginUriTemplate: String = services.loginUriTemplate
val collectionsUri: String = services.collectionsBaseUri

val requiredMetadata = NonEmptyList("credit", "description", "usageRights")
Expand Down
2 changes: 0 additions & 2 deletions metadata-editor/app/MetadataEditorComponents.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import com.gu.mediaservice.lib.imaging.ImageOperations
import com.gu.mediaservice.lib.management.InnerServiceStatusCheckController
import com.gu.mediaservice.lib.play.GridComponents
import controllers.{EditsApi, EditsController, SyndicationController}
Expand All @@ -12,7 +11,6 @@ class MetadataEditorComponents(context: Context) extends GridComponents(context,
val editsStore = new EditsStore(config)
val syndicationStore = new SyndicationStore(config)
val notifications = new Notifications(config)
val imageOperations = new ImageOperations(context.environment.rootPath.getAbsolutePath)

val metrics = new MetadataEditorMetrics(config, actorSystem, applicationLifecycle)
val messageConsumer = new MetadataSqsMessageConsumer(config, metrics, editsStore)
Expand Down
5 changes: 0 additions & 5 deletions metadata-editor/app/lib/EditsConfig.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package lib

import com.amazonaws.regions.{Region, RegionUtils}
import com.gu.mediaservice.lib.config.{CommonConfig, GridConfigResources}


class EditsConfig(resources: GridConfigResources) extends CommonConfig(resources) {
val dynamoRegion: Region = RegionUtils.getRegion(string("aws.region"))

val collectionsBucket: String = string("s3.collections.bucket")

val editsTable = string("dynamo.table.edits")
val editsTablePhotoshootIndex = string("dynamo.globalsecondaryindex.edits.photoshoots")
val syndicationTable = string("dynamo.table.syndication")
Expand Down
7 changes: 0 additions & 7 deletions usage/app/lib/UsageConfig.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package lib

import com.amazonaws.regions.{Region, RegionUtils}
import com.amazonaws.services.identitymanagement._
import com.gu.mediaservice.lib.config.{CommonConfig, GridConfigResources}
import com.gu.mediaservice.lib.logging.GridLogging
Expand All @@ -12,13 +11,9 @@ import scala.util.Try
case class KinesisReaderConfig(streamName: String, arn: String, appName: String)

class UsageConfig(resources: GridConfigResources) extends CommonConfig(resources) with GridLogging {
val rootUri: String = services.metadataBaseUri
val kahunaUri: String = services.kahunaBaseUri
val usageUri: String = services.usageBaseUri
val apiUri: String = services.apiBaseUri
val loginUriTemplate: String = services.loginUriTemplate

val defaultPageSize = 100
val defaultMaxRetries = 4
val defaultMaxPrintRequestSizeInKb = 500
val defaultDateLimit = "2016-01-01T00:00:00+00:00"
Expand All @@ -29,7 +24,6 @@ class UsageConfig(resources: GridConfigResources) extends CommonConfig(resources
val capiPreviewUrl = string("capi.preview.url")
val capiPreviewRole = stringOpt("capi.preview.role")
val capiApiKey = string("capi.apiKey")
val capiPageSize: Int = intDefault("capi.page.size", defaultPageSize)
val capiMaxRetries: Int = intDefault("capi.maxRetries", defaultMaxRetries)

val usageDateLimit: String = stringDefault("usage.dateLimit", defaultDateLimit)
Expand All @@ -41,7 +35,6 @@ class UsageConfig(resources: GridConfigResources) extends CommonConfig(resources

val usageRecordTable = string("dynamo.tablename.usageRecordTable")

val dynamoRegion: Region = RegionUtils.getRegion(string("aws.region"))
val awsRegionName = string("aws.region")

private val iamClient: AmazonIdentityManagement = withAWSCredentials(AmazonIdentityManagementClientBuilder.standard()).build()
Expand Down

0 comments on commit da4e5a1

Please sign in to comment.