Moved sthome kacgae to pkg/dns. Simplified config.go

This commit is contained in:
Chris Stuurman 2024-04-05 19:53:43 +02:00
parent 99642343d1
commit 5b51498b5b
14 changed files with 33 additions and 25 deletions

View File

@ -1,5 +1,5 @@
apiVersion: v1 apiVersion: v1
appVersion: v0.0.4-alpha.100 appVersion: v0.0.4-alpha.107
description: Cert-Manager webhook for sthome description: Cert-Manager webhook for sthome
name: sthome-webhook name: sthome-webhook
version: 0.0.4-alpha.100 version: 0.0.4-alpha.107

View File

@ -31,7 +31,7 @@ clusterIssuer:
image: image:
repository: stuurmcp/cert-manager-webhook-sthome repository: stuurmcp/cert-manager-webhook-sthome
#repository: wstat.sthome.net:5000/cert-manager-webhook-sthome #repository: wstat.sthome.net:5000/cert-manager-webhook-sthome
tag: 0.0.4-alpha.100 tag: 0.0.4-alpha.107
#pullPolicy should be IfNotPresent. Set to Always for testing purposes #pullPolicy should be IfNotPresent. Set to Always for testing purposes
pullPolicy: IfNotPresent pullPolicy: IfNotPresent

4
go.mod
View File

@ -6,8 +6,7 @@ toolchain go1.22.1
require ( require (
github.com/cert-manager/cert-manager v1.14.4 github.com/cert-manager/cert-manager v1.14.4
github.com/miekg/dns v1.1.58 github.com/miekg/dns v1.1.58 // indirect
github.com/stretchr/testify v1.8.4
k8s.io/api v0.29.0 k8s.io/api v0.29.0
k8s.io/apiextensions-apiserver v0.29.0 k8s.io/apiextensions-apiserver v0.29.0
k8s.io/client-go v0.29.0 k8s.io/client-go v0.29.0
@ -59,7 +58,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect github.com/prometheus/common v0.45.0 // indirect

View File

@ -8,7 +8,7 @@ import (
"github.com/cert-manager/cert-manager/pkg/acme/webhook/cmd" "github.com/cert-manager/cert-manager/pkg/acme/webhook/cmd"
"github.com/stuurmcp/cert-manager-webhook-sthome/sthome" sthome "github.com/stuurmcp/cert-manager-webhook-sthome/pkg/dns"
) )
var ( var (

View File

@ -1,4 +1,4 @@
package sthome package dns
import ( import (
"strings" "strings"
@ -39,26 +39,26 @@ type LocalDNSProviderConfig struct {
// secret which contains the sthome API Key. // secret which contains the sthome API Key.
APIKeySecretRef v1.SecretKeySelector `json:"apiKeySecretRef"` APIKeySecretRef v1.SecretKeySelector `json:"apiKeySecretRef"`
// Host is the Base URL (e.g. https://dns.example.ca) of the sthome API. // Host is the Base URL (e.g. https://dns.example.ca) of the sthome API.
Host string `json:"host"` //Host string `json:"host"`
// Scheme supports HTTP AuthSchemes // Scheme supports HTTP AuthSchemes
// https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml // https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml
// //
// +optional default "" // +optional default ""
APIKeyScheme string `json:"apiKeyScheme"` //APIKeyScheme string `json:"apiKeyScheme"`
// APIKeyHeaderName is the header name where apiKey will be set // APIKeyHeaderName is the header name where apiKey will be set
// //
// +optional default "X-API-Key" // +optional default "X-API-Key"
APIKeyHeaderName string `json:"apiKeyHeaderName"` //APIKeyHeaderName string `json:"apiKeyHeaderName"`
// ServerID is the server ID in the sthome API. // ServerID is the server ID in the sthome API.
// When unset, defaults to "localhost". // When unset, defaults to "localhost".
ServerID string `json:"serverID"` //ServerID string `json:"serverID"`
// Headers are additional headers added to requests to the // Headers are additional headers added to requests to the
// sthome API server. // sthome API server.
Headers map[string]string `json:"headers"` //Headers map[string]string `json:"headers"`
// CABundle is a PEM encoded CA bundle which will be used in // CABundle is a PEM encoded CA bundle which will be used in
// certificate validation when connecting to the sthome server. // certificate validation when connecting to the sthome server.
@ -66,18 +66,18 @@ type LocalDNSProviderConfig struct {
// When left blank, the default system store will be used. // When left blank, the default system store will be used.
// //
// +optional // +optional
CABundle []byte `json:"caBundle"` //CABundle []byte `json:"caBundle"`
// TTL is the time-to-live value of the inserted DNS records. // TTL is the time-to-live value of the inserted DNS records.
// //
// +optional // +optional
TTL int `json:"ttl"` //TTL int `json:"ttl"`
// Timeout is the timeout value for requests to the sthome API. // Timeout is the timeout value for requests to the sthome API.
// The value is specified in seconds. // The value is specified in seconds.
// //
// +optional // +optional
Timeout int `json:"timeout"` //Timeout int `json:"timeout"`
// AllowedZones is the list of zones that may be edited. If the list is // AllowedZones is the list of zones that may be edited. If the list is
// empty, all zones are permitted. // empty, all zones are permitted.

View File

@ -1,4 +1,4 @@
package sthome package dns
import ( import (
"bytes" "bytes"

View File

@ -1,4 +1,4 @@
package sthome package dns
import ( import (
"fmt" "fmt"
@ -47,7 +47,7 @@ func (p *LocalDNSProviderSolver) Name() string {
// cert-manager itself will later perform a self check to ensure that the // cert-manager itself will later perform a self check to ensure that the
// solver has correctly configured the DNS provider. // solver has correctly configured the DNS provider.
func (loc *LocalDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error { func (loc *LocalDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
domainName := extractDomainName(ch.ResolvedZone) //domainName := extractDomainName(ch.ResolvedZone)
cfg, err := loadConfig(ch.Config) cfg, err := loadConfig(ch.Config)
if err != nil { if err != nil {
return err return err
@ -80,7 +80,17 @@ func (loc *LocalDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error
*/ */
// TODO: do something more useful with the decoded configuration // TODO: do something more useful with the decoded configuration
klog.Infof("Decoded configuration %v\n", cfg) klog.Infof("Decoded configuration %v\n", cfg)
klog.Infof("Presenting record for %s, ch: %s, domain: %s", ch.DNSName, ch.ResolvedFQDN, domainName) klog.Infof("Presenting record for %s, type: %s, uid: %s, key: %s, ns: %s, fqdn: %s, zone: %s, allowambcred: %t, cfg: %s",
ch.DNSName,
ch.UID,
ch.Type,
ch.Key,
ch.ResourceNamespace,
ch.ResolvedFQDN,
ch.ResolvedZone,
ch.AllowAmbientCredentials,
ch.Config,
)
// TODO: convert shell script to golang // TODO: convert shell script to golang
localip := getOutboundIP(dnsserver_net) localip := getOutboundIP(dnsserver_net)
success, _ := Execute( success, _ := Execute(

View File

@ -1,7 +1,7 @@
// private repo workaround // private repo workaround
// Will use this file and remove same content from main.go when github repo is made public // Will use this file and remove same content from main.go when github repo is made public
package sthome package dns
import ( import (
"encoding/json" "encoding/json"

View File

@ -1,4 +1,4 @@
package sthome package dns
import ( import (
"context" "context"

View File

@ -1,3 +1,3 @@
0.0.4-alpha.100 0.0.4-alpha.107
20240402-1118 20240405-1950
100 107