From 97f668adc60594d7c2aada566b38df1d747706f7 Mon Sep 17 00:00:00 2001 From: Hector Geraldino Date: Mon, 23 Aug 2021 18:13:13 -0400 Subject: [PATCH] Store checksun info for downloadable artifacts (see #540) --- .../io/sdkman/changelogs/MavenMigration.scala | 46 ++++++++++++++ .../scala/io/sdkman/changelogs/package.scala | 60 ++++++++++++++++++- 2 files changed, 103 insertions(+), 3 deletions(-) diff --git a/src/main/scala/io/sdkman/changelogs/MavenMigration.scala b/src/main/scala/io/sdkman/changelogs/MavenMigration.scala index b39a1ea8c..a3c0e4bf4 100644 --- a/src/main/scala/io/sdkman/changelogs/MavenMigration.scala +++ b/src/main/scala/io/sdkman/changelogs/MavenMigration.scala @@ -83,4 +83,50 @@ class MavenMigration { .asCandidateDefault() } + @ChangeSet(order = "007", id = "007-add_checksums", author = "hgeraldino") + def migration007(implicit db: MongoDatabase) = { + updateChecksum( + "maven", + "3.5.4", + Universal, + SHA512, + "4d2763e1b73dfcde5c955f586bd754443833f63e20dd9ce4ce4405a2010bfc48324aa3b6bd5b6ac71a614112734b0bc652aa2ac05f492ed28a66de8116c3ef6e" + ) + updateChecksum( + "maven", + "3.6.0", + Universal, + SHA512, + "7d14ab2b713880538974aa361b987231473fbbed20e83586d542c691ace1139026f232bd46fdcce5e8887f528ab1c3fbfc1b2adec90518b6941235952d3868e9" + ) + updateChecksum( + "maven", + "3.6.1", + Universal, + SHA512, + "51169366d7269ed316bad013d9cbfebe3a4ef1fda393ac4982d6dbc9af2d5cc359ee12838b8041cb998f236486e988b9c05372f4fdb29a96c1139f63c991e90e" + ) + updateChecksum( + "maven", + "3.6.2", + Universal, + SHA512, + "4bb0e0bb1fb74f1b990ba9a6493cc6345873d9188fc7613df16ab0d5bd2017de5a3917af4502792f0bad1fcc95785dcc6660f7add53548e0ec4bfb30ce4b1da7" + ) + updateChecksum( + "maven", + "3.6.3", + Universal, + SHA512, + "1c095ed556eda06c6d82fdf52200bc4f3437a1bab42387e801d6f4c56e833fb82b16e8bf0aab95c9708de7bfb55ec27f653a7cf0f491acebc541af234eded94d" + ) + updateChecksum( + "maven", + "3.8.1", + Universal, + SHA512, + "c585847bfbcf8647aeabfd3e8bf0ac3f67a037bd345545e274766f144c2b978b3457cbc3e31545e62c21ad69e732695de01ec96ea2580e5da67bd85df095c0f4" + ) + } + } diff --git a/src/main/scala/io/sdkman/changelogs/package.scala b/src/main/scala/io/sdkman/changelogs/package.scala index 2b74ed6ff..7210e2aa4 100644 --- a/src/main/scala/io/sdkman/changelogs/package.scala +++ b/src/main/scala/io/sdkman/changelogs/package.scala @@ -28,9 +28,9 @@ package object changelogs { new Validator[Version] with UrlValidation with LazyLogging { override def validVersion(v: Version): Unit = v match { - case Version("java", version, _, _, _) => + case Version("java", version, _, _, _, _, _) => if (version.length > 17) throw exception(version) - case Version(_, version, _, _, _) => + case Version(_, version, _, _, _, _, _) => if (version.length > 15) throw exception(version) } @@ -186,6 +186,30 @@ package object changelogs { override val id = "LINUX_ARM32" } + sealed trait HashAlgorithm { + def id: String + } + + case object SHA1 extends HashAlgorithm { + override val id = "SHA-1" + } + + case object SHA224 extends HashAlgorithm { + override val id = "SHA-224" + } + + case object SHA256 extends HashAlgorithm { + override val id = "SHA-256" + } + + case object SHA384 extends HashAlgorithm { + override val id = "SHA-384" + } + + case object SHA512 extends HashAlgorithm { + override val id = "SHA-512" + } + case class Candidate( candidate: String, name: String, @@ -200,7 +224,9 @@ package object changelogs { version: String, url: String, platform: Platform = Universal, - vendor: Option[Vendor] = None + vendor: Option[Vendor] = None, + hashAlgorithm: Option[HashAlgorithm] = None, + checksum: Option[String] = None ) def candidateToDocument(c: Candidate): Document = { @@ -236,6 +262,12 @@ package object changelogs { cv.vendor.fold(doc) { vendor => doc.append("vendor", vendor.id) } + cv.hashAlgorithm.fold(doc) { algorithm => + doc.append("algorithm", algorithm.id) + } + cv.checksum.fold(doc) { hash => + doc.append("hash", hash) + } } private def buildVersionDocument( @@ -294,4 +326,26 @@ package object changelogs { Filters.eq("candidate", candidate), Updates.set("default", version) ) + + def updateChecksum( + candidate: String, + version: String, + platform: Platform, + hashAlgorithm: HashAlgorithm, + checksum: String + )( + implicit db: MongoDatabase + ): Unit = + db.getCollection(VersionsCollection) + .findOneAndUpdate( + Filters.and( + Filters.eq("candidate", candidate), + Filters.eq("version", version), + Filters.eq("platform", platform.id) + ), + Updates.combine( + Updates.set("algorithm", hashAlgorithm.id), + Updates.set("checksum", checksum) + ) + ) }