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

Add checksums #541

Closed
wants to merge 2 commits into from
Closed
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
47 changes: 46 additions & 1 deletion src/main/scala/io/sdkman/changelogs/MavenMigration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class MavenMigration {
).validate()
.insert()
.asCandidateDefault()
}
}

@ChangeSet(order = "007", id = "007-add_maven_3.8.2", author = "clemstoquart")
def migration007(implicit db: MongoDatabase) = {
Expand All @@ -92,6 +92,51 @@ class MavenMigration {
).validate()
.insert()
.asCandidateDefault()

@ChangeSet(order = "008", id = "008-add_checksums", author = "hgeraldino")
def migration008(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"
)
}

}
60 changes: 57 additions & 3 deletions src/main/scala/io/sdkman/changelogs/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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,
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if that entirely makes sense. Can a checksum exist without an algorithm? These two together should probably have a case class of their own, and that should be an option.
Something like:

case class Checksum(algorithm: HashAlgorithm, value: String)
...
checksum: Option[Checksum]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. But if this is slowing down the pull request, I'd be to contribute an edit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stewSquared perhaps you aren't getting the context here, but you are looking at the database migration project. This will be the last thing to be implemented. It is also the least important of the lot.

We are driving this feature from the client side, and are currently focusing on the CLI. After that we will do the crucial work in the broker, followed by all the other auxillary services.

At the moment, everything works on the client, with the exception of one small bug that we've encountered with cached archives. The fix will be released soon. Checksums will be released into the wild when we think it's ready, not a moment sooner.

)

def candidateToDocument(c: Candidate): Document = {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
)
)
}