From 988339323fceedc2aa8be3fd634627df2e49013f Mon Sep 17 00:00:00 2001 From: jerger Date: Sat, 12 Feb 2022 20:50:21 +0100 Subject: [PATCH] fix issuer url & tests --- .../server/domain/CertmanagerEndpoint.kt | 9 ++++++++- .../provs/server/infrastructure/K3s.kt | 3 ++- .../k3s/le-issuer.template.yaml | 6 +++--- .../server/domain/CertmanagerEndpointTest.kt | 20 +++++++++++++++++++ .../server/infrastructure/NetworkKtTest.kt | 2 +- .../k3s/ConfigRepositoryTest.kt | 2 +- 6 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 src/test/kotlin/org/domaindrivenarchitecture/provs/server/domain/CertmanagerEndpointTest.kt diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/CertmanagerEndpoint.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/CertmanagerEndpoint.kt index 037902b..a6b1178 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/CertmanagerEndpoint.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/CertmanagerEndpoint.kt @@ -1,5 +1,12 @@ package org.domaindrivenarchitecture.provs.server.domain enum class CertmanagerEndpoint { - staging, prod + staging, prod; + + fun endpointUri(): String { + return if (this == staging) + "https://acme-staging-v02.api.letsencrypt.org/directory" + else + "https://acme-v02.api.letsencrypt.org/directory" + } } \ No newline at end of file diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt index 7fccccb..2799324 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt @@ -103,7 +103,8 @@ fun Prov.provisionK3sCertManager(certmanager: Certmanager) = task { "le-issuer.template.yaml", k3sResourcePath, mapOf( - "endpoint" to certmanager.letsencryptEndpoint.name.lowercase(), + "endpoint" to certmanager.letsencryptEndpoint.endpointUri(), + "name" to certmanager.letsencryptEndpoint.name.lowercase(), "email" to certmanager.email ), "644", diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/le-issuer.template.yaml b/src/main/resources/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/le-issuer.template.yaml index d4ab188..71c6d35 100644 --- a/src/main/resources/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/le-issuer.template.yaml +++ b/src/main/resources/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/le-issuer.template.yaml @@ -1,13 +1,13 @@ apiVersion: cert-manager.io/v1 kind: ClusterIssuer metadata: - name: ${endpoint} + name: ${name} spec: acme: email: ${email} - server: https://acme-${endpoint}-v02.api.letsencrypt.org/directory + server: ${endpoint} privateKeySecretRef: - name: ${endpoint} + name: ${name} solvers: - http01: ingress: diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/domain/CertmanagerEndpointTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/domain/CertmanagerEndpointTest.kt new file mode 100644 index 0000000..97597c0 --- /dev/null +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/domain/CertmanagerEndpointTest.kt @@ -0,0 +1,20 @@ +package org.domaindrivenarchitecture.provs.server.domain + +import org.domaindrivenarchitecture.provs.server.domain.ServerType +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.Assertions.* + +internal class CertmanagerEndpointTest { + + @Test + fun shouldResultCorrectEndpoint() { + // given + val cut = CertmanagerEndpoint.prod + + // when + val result = cut.endpointUri() + + // then + assertEquals("https://acme-v02.api.letsencrypt.org/directory", result) + } +} \ No newline at end of file diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/NetworkKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/NetworkKtTest.kt index ab88f95..9bb7095 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/NetworkKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/NetworkKtTest.kt @@ -35,7 +35,7 @@ internal class NetworkKtTest { loopback = Loopback("192.168.5.1", "fc00::5:1"), certmanager = Certmanager( email = "admin@meissa-gmbh.de", - letsencryptEndpoint = CertmanagerEndpoint.PROD + letsencryptEndpoint = CertmanagerEndpoint.prod ), apple = true, reprovision = true diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/ConfigRepositoryTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/ConfigRepositoryTest.kt index 9e1f943..04d3d02 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/ConfigRepositoryTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/ConfigRepositoryTest.kt @@ -27,7 +27,7 @@ internal class ConfigRepositoryTest { loopback = Loopback("192.168.5.1", "fc00::5:1"), certmanager = Certmanager( email = "admin@meissa-gmbh.de", - letsencryptEndpoint = CertmanagerEndpoint.PROD + letsencryptEndpoint = CertmanagerEndpoint.prod ), apple = true, reprovision = true