Skip to content

Commit

Permalink
sorted reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdjulian committed Jun 25, 2023
1 parent c9c0800 commit 231f072
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object NativeImageSmokeTest {
@JvmStatic
fun main(args: Array<String>) {
val kanikoClient = BlockingContainerImageClientFactory.create(
credentials = RegistryCredentials("cmdjulian", "R!rb8pm53%ws9dg&24NTMFasH*AMadmX"),
credentials = RegistryCredentials("cmdjulian", "changeMe"),
)
val kaniko = ContainerImageName.parse("cmdjulian/kaniko:v1.8.1")
extracted(kanikoClient, kaniko)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
{
"name": "[Ljava.lang.String;"
},
{
"name": "[Lsun.security.pkcs.SignerInfo;"
},
{
"name": "com.fasterxml.jackson.databind.PropertyNamingStrategies$LowerDotCaseStrategy",
"methods": [
Expand Down Expand Up @@ -353,6 +350,15 @@
{
"name": "de.cmdjulian.kirc.spec.manifest.OciManifestV1"
},
{
"name": "java.io.ObjectInputStream"
},
{
"name": "java.io.Serializable",
"allDeclaredFields": true,
"allDeclaredClasses": true,
"queryAllDeclaredMethods": true
},
{
"name": "java.lang.Boolean"
},
Expand Down Expand Up @@ -427,31 +433,16 @@
]
},
{
"name": "kotlin.Any"
},
{
"name": "kotlin.Array"
},
{
"name": "kotlin.Boolean"
},
{
"name": "kotlin.Byte"
},
{
"name": "kotlin.Char"
},
{
"name": "kotlin.Comparable"
"name": "java.time.OffsetDateTime"
},
{
"name": "kotlin.Enum"
"name": "java.util.Date"
},
{
"name": "kotlin.Int"
"name": "java.util.List"
},
{
"name": "kotlin.Long"
"name": "java.util.Map"
},
{
"name": "kotlin.Metadata",
Expand Down Expand Up @@ -491,18 +482,6 @@
}
]
},
{
"name": "kotlin.String"
},
{
"name": "kotlin.Unit"
},
{
"name": "kotlin.collections.List"
},
{
"name": "kotlin.collections.Map"
},
{
"name": "kotlin.jvm.internal.DefaultConstructorMarker"
},
Expand All @@ -518,26 +497,5 @@
{
"name": "kotlin.reflect.jvm.internal.impl.resolve.scopes.DescriptorKindFilter",
"allPublicFields": true
},
{
"name": "java.time.OffsetDateTime"
},
{
"name": "java.util.Date"
},
{
"name": "java.util.List"
},
{
"name": "java.util.Map"
},
{
"name": "java.io.ObjectInputStream"
},
{
"name": "java.io.Serializable",
"allDeclaredFields": true,
"allDeclaredClasses": true,
"queryAllDeclaredMethods": true
}
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package de.cmdjulian.kirc.image

import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonValue

data class ContainerImageNameComponents(
val registry: Registry?,
val repository: Repository,
Expand Down Expand Up @@ -57,6 +60,7 @@ class ContainerImageName(
return result
}

@JsonValue
override fun toString(): String {
val tagComponent = tag?.asImagePart() ?: ""
val digestComponent = digest?.asImagePart() ?: ""
Expand All @@ -68,6 +72,7 @@ class ContainerImageName(
const val DOCKER_HUB_REGISTRY = "docker.io"

@JvmStatic
@JsonCreator
fun parse(image: String): ContainerImageName {
val (registry, repository, tag, digest) = parseComponents(image)

Expand Down
12 changes: 10 additions & 2 deletions kirc-image/src/main/kotlin/de/cmdjulian/kirc/image/Reference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sealed interface Reference {
fun asImagePart() = "$separator${toString()}"
}

class Tag @JsonCreator constructor(@JsonValue private val value: String) : Reference {
class Tag(@JsonValue private val value: String) : Reference {
init {
require(value.matches(Regex("\\w[\\w.\\-]{0,127}"))) { "invalid tag" }
}
Expand All @@ -23,10 +23,14 @@ class Tag @JsonCreator constructor(@JsonValue private val value: String) : Refer
companion object {
val LATEST = Tag("latest")
const val separator: Char = ':'

@JvmStatic
@JsonCreator
fun of(tag: String) = Tag(tag)
}
}

class Digest @JsonCreator constructor(@JsonValue private val value: String) : Reference, Comparable<Digest> {
class Digest(@JsonValue private val value: String) : Reference, Comparable<Digest> {
init {
require(value.matches(Regex("sha256:[\\da-fA-F]{32,}"))) { "invalid digest" }
}
Expand All @@ -41,5 +45,9 @@ class Digest @JsonCreator constructor(@JsonValue private val value: String) : Re

companion object {
const val separator: Char = '@'

@JvmStatic
@JsonCreator
fun of(digest: String) = Digest(digest)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ package de.cmdjulian.kirc.image
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonValue

class Registry @JsonCreator constructor(@JsonValue private val value: String) {
class Registry(@JsonValue private val value: String) {
//language=RegExp
companion object {
private const val IP_ADDRESS = "(((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4})"
private const val DOMAIN = "(([a-zA-Z\\d_\\-]+)((\\.[a-zA-Z\\d_\\-]+)*))"
private const val PORT =
"(:(6553[0-5]|655[0-2][0-9]\\d|65[0-4](\\d){2}|6[0-4](\\d){3}|[1-5](\\d){4}|[1-9](\\d){0,3}))"
val regex = Regex("^($IP_ADDRESS|$DOMAIN)$PORT?\$")

@JvmStatic
@JsonCreator
fun of(registry: String) = Registry(registry)
}

init {
Expand Down
10 changes: 8 additions & 2 deletions kirc-image/src/main/kotlin/de/cmdjulian/kirc/image/Repository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package de.cmdjulian.kirc.image
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonValue
import java.nio.file.Path
import java.util.Locale
import java.util.*

class Repository @JsonCreator constructor(@JsonValue private val value: String) {
class Repository(@JsonValue private val value: String) {
init {
require(!Path.of(value).isAbsolute) { "invalid repository, has to be relative" }
require(value == value.lowercase(Locale.getDefault())) {
Expand All @@ -21,4 +21,10 @@ class Repository @JsonCreator constructor(@JsonValue private val value: String)
override fun equals(other: Any?): Boolean = other is Repository && other.value == value
override fun hashCode(): Int = value.hashCode()
override fun toString(): String = value

companion object {
@JvmStatic
@JsonCreator
fun of(repository: String) = Repository(repository)
}
}
Loading

0 comments on commit 231f072

Please sign in to comment.