Skip to content

Commit

Permalink
Merge pull request #1280 from adoptium/main
Browse files Browse the repository at this point in the history
Merge main to prod
  • Loading branch information
johnoliver authored Nov 26, 2024
2 parents da9e39a + 0f92ee0 commit 1eef5d3
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4
uses: github/codeql-action/init@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -59,6 +59,6 @@ jobs:
./mvnw --batch-mode clean install -Padoptium,-adoptopenjdk
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4
uses: github/codeql-action/analyze@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
with:
category: "/language:${{matrix.language}}"
2 changes: 1 addition & 1 deletion adoptium-api-versions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<maven.project-info-reports-plugin.version>3.8.0</maven.project-info-reports-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.version>3.16.3</quarkus.version>
<quarkus.version>3.17.0</quarkus.version>
<rest-assured.version>5.5.0</rest-assured.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import net.adoptium.api.v3.dataSources.APIDataStore
import org.jboss.resteasy.reactive.common.headers.CacheControlDelegate
import org.jboss.resteasy.reactive.common.util.ExtendedCacheControl
import org.jboss.resteasy.reactive.server.ServerResponseFilter
import java.math.BigInteger
import java.security.MessageDigest
import java.util.*


@Provider
Expand All @@ -28,9 +31,19 @@ class CacheControlService @Inject constructor(private var apiDataStore: APIDataS
return CACHE_CONTROLLED_PATHS.any { path.startsWith(it) }
}

private fun calculateEtag(requestContext: ContainerRequestContext): String {
val md = MessageDigest.getInstance("SHA1")
if (apiDataStore.getUpdateInfo().hexChecksum != null) {
md.update(HexFormat.of().parseHex(apiDataStore.getUpdateInfo().hexChecksum))
}
md.update(requestContext.uriInfo.requestUri.toString().toByteArray())
return BigInteger(1, md.digest()).toString(16)
}

override fun filter(requestContext: ContainerRequestContext?) {
if (isCacheControlledPath(requestContext)) {
val etag = apiDataStore.getUpdateInfo().hexChecksum
val etag = calculateEtag(requestContext!!)

val lastModified = apiDataStore.getUpdateInfo().lastModified

if (lastModified == null || etag == null) {
Expand All @@ -51,6 +64,7 @@ class CacheControlService @Inject constructor(private var apiDataStore: APIDataS
@ServerResponseFilter
fun responseFilter(requestContext: ContainerRequestContext?, responseContext: ContainerResponseContext?) {
if (isCacheControlledPath(requestContext)) {

val ecc = ExtendedCacheControl();
ecc.isPublic = true
ecc.maxAge = MAX_CACHE_AGE_IN_SEC
Expand All @@ -61,7 +75,9 @@ class CacheControlService @Inject constructor(private var apiDataStore: APIDataS
return
}

responseContext?.headers?.add("ETag", apiDataStore.getUpdateInfo().hexChecksum)
val etag = calculateEtag(requestContext!!)

responseContext?.headers?.add("ETag", etag)
responseContext?.headers?.add("Last-Modified", apiDataStore.getUpdateInfo().lastModifiedFormatted)
responseContext?.headers?.add("Cache-Control", CacheControlDelegate.INSTANCE.toString(ecc))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,15 @@ class AssetsResourceFeatureReleasePathTest : AssetsPathTest() {
.statusCode(200)
.assertThat()
.header("Cache-Control", Matchers.equalTo("public, no-transform, s-maxage=120, max-age=120"))
.header("ETag", Matchers.equalTo("d76df8e7aefcf7"))
.header("ETag", Matchers.equalTo("808bc9e876e1dd5e15b8eb3377618e1c1b313a1e"))
.header("Last-Modified", Matchers.notNullValue())
}

@Test
fun `if none match applied`() {
RestAssured.given()
.`when`()
.header("If-None-Match", "d76df8e7aefcf7")
.header("If-None-Match", "808bc9e876e1dd5e15b8eb3377618e1c1b313a1e")
.get("/v3/assets/feature_releases/8/ga")
.then()
.statusCode(304)
Expand All @@ -268,7 +268,7 @@ class AssetsResourceFeatureReleasePathTest : AssetsPathTest() {
fun `etag applied match applied`() {
RestAssured.given()
.`when`()
.header("If-Match", "d76df8e7aefcf7")
.header("If-Match", "808bc9e876e1dd5e15b8eb3377618e1c1b313a1e")
.get("/v3/assets/feature_releases/8/ga")
.then()
.statusCode(200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class V3Updater @Inject constructor(
private val LOGGER = LoggerFactory.getLogger(this::class.java)

fun calculateChecksum(repo: AdoptRepos): String {
val md = MessageDigest.getInstance("MD5")
val md = MessageDigest.getInstance("SHA256")
val outputStream = object : OutputStream() {
override fun write(b: Int) {
md.update(b.toByte())
Expand Down Expand Up @@ -269,6 +269,8 @@ class V3Updater @Inject constructor(
LOGGER.info("Updating Release Notes")
adoptReleaseNotes.updateReleaseNotes(repo)

printRepoDebugInfo(currentRepo, repo, repo)

LOGGER.info("Full update done")
return@runBlocking repo
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class V3UpdaterTest {
fun `checksum works`() {
runBlocking {
val checksum = V3Updater.calculateChecksum(BaseTest.adoptRepos)
assertTrue(checksum.length == 24)
assertTrue(checksum.length == 44)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<maven.jdeps-plugin.version>3.1.2</maven.jdeps-plugin.version>
<maven.jxr-plugin.version>3.6.0</maven.jxr-plugin.version>
<maven.license-plugin.version>2.4.0</maven.license-plugin.version>
<maven.openapi-generator-maven-plugin.version>7.9.0</maven.openapi-generator-maven-plugin.version>
<maven.openapi-generator-maven-plugin.version>7.10.0</maven.openapi-generator-maven-plugin.version>
<maven.pitest-plugin.version>1.17.1</maven.pitest-plugin.version>
<maven.pmd-plugin.version>3.26.0</maven.pmd-plugin.version>
<maven.project-info-reports-plugin.version>3.8.0</maven.project-info-reports-plugin.version>
Expand All @@ -82,7 +82,7 @@
<spotbugs.version>4.7.3</spotbugs.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.version>3.16.3</quarkus.version>
<quarkus.version>3.17.0</quarkus.version>
</properties>

<modules>
Expand Down

0 comments on commit 1eef5d3

Please sign in to comment.