Added Nickel constraint on values.

This commit is contained in:
antux18 2024-07-17 14:56:38 +02:00
parent 6897091c0d
commit d791064183
2 changed files with 23 additions and 10 deletions

View File

@ -1,3 +1,4 @@
let { Artifact, .. } = import "../workflow/nickel/artifact_contract.ncl" in
{
artifact_url = "https://example.com/artifact.zip",
type = "zip",
@ -9,6 +10,6 @@
{ name = "pkg1", location = "path/to/git/repo"}
],
misc_packages = [
{ name = "mpkg1", url = "https://", type = "zip" }
],
}
{ name = "mpkg1", url = "http://example.com/package.zip", type = "zip" }
]
} | Artifact

View File

@ -1,7 +1,10 @@
let
conf = {
ARCHIVE_FORMATS = ["zip", "tar"],
PACKAGE_MANAGERS = ["dpkg", "rpm", "pacman", "pip", "conda"]
PACKAGE_MANAGERS = ["dpkg", "rpm", "pacman", "pip", "conda"],
FILEPATH_REGEX = "^[^\\x00]+$", # For UNIX, anything of length > 0 but without NULL characters, found at: https://stackoverflow.com/questions/537772/what-is-the-most-correct-regular-expression-for-a-unix-file-path
URL_REGEX = "^https?:\\/\\/(?:www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$", # Found at: https://uibakery.io/regex-library/url
IMAGENAME_REGEX = "^[a-z0-9]+(([.]{0,1}|[_]{0,2}|[-]*)[a-z0-9]+)*(:[a-zA-Z0-9_]+[a-zA-Z0-9._-]*){0,1}$" # Based on, with modifications: https://regexr.com/3bsog
}
in
{
@ -11,13 +14,22 @@ in
ArchiveType = std.contract.from_predicate (
fun value => std.array.any (fun x => x == value) conf.ARCHIVE_FORMATS
),
FilePath = std.contract.from_predicate (
fun value => std.string.is_match conf.FILEPATH_REGEX value
),
URL = std.contract.from_predicate (
fun value => std.string.is_match conf.URL_REGEX value
),
ImageName = std.contract.from_predicate (
fun value => (std.string.is_match conf.IMAGENAME_REGEX value) && (std.string.length value < 128) # Length could be more than 128, but it's easier that way...
),
GitPackage = {
name
| doc "Name of the package for future identification"
| String,
location
| doc "Path where cloned in the container"
| String
| FilePath
},
MiscPackage = {
name
@ -25,7 +37,7 @@ in
| String,
url
| doc "URL of the package. Will be used to compute the hash"
| String,
| URL,
type
| doc "Type of the archive (zip, tar, ...)"
| ArchiveType,
@ -33,7 +45,7 @@ in
Artifact = {
artifact_url
| doc "URL where to download the artifact"
| String,
| URL,
type
| doc "Type of the archive (zip, tar, ...)"
| ArchiveType,
@ -42,10 +54,10 @@ in
| String,
image_name
| doc "Name to give the image when building"
| String,
| ImageName,
dockerfile_location
| doc "Path to the dockerfile in the artifact"
| String,
| FilePath,
package_managers
| doc "Package Managers used in the container"
| Array PackageManager,