Capitalised functions/structs for export

This commit is contained in:
Chris Stuurman 2024-03-24 15:35:09 +02:00
parent ca6f5facba
commit 5c1530e21f
6 changed files with 23 additions and 15 deletions

2
go.mod
View File

@ -5,6 +5,8 @@ go 1.21
toolchain go1.22.1
require (
/// uncomment and fix tag when github repo is made public
//github.com/stuurmcp/cert-manager-webhook-sthome v0.0.1-alpha
github.com/cert-manager/cert-manager v1.14.4
github.com/miekg/dns v1.1.58
github.com/stretchr/testify v1.8.4

View File

@ -4,6 +4,7 @@ import (
"os"
"github.com/cert-manager/cert-manager/pkg/acme/webhook/cmd"
"github.com/stuurmcp/cert-manager-webhook-sthome/sthome"
)
@ -14,6 +15,6 @@ func main() {
panic("GROUP_NAME must be specified")
}
cmd.RunWebhookServer(GroupName,
&sthome.localDNSProviderSolver{},
&sthome.LocalDNSProviderSolver{},
)
}

View File

@ -7,7 +7,7 @@ import (
"github.com/miekg/dns"
)
func (e *sthomeSolver) handleDNSRequest(w dns.ResponseWriter, req *dns.Msg) {
func (e *SthomeSolver) handleDNSRequest(w dns.ResponseWriter, req *dns.Msg) {
msg := new(dns.Msg)
msg.SetReply(req)
switch req.Opcode {
@ -22,7 +22,7 @@ func (e *sthomeSolver) handleDNSRequest(w dns.ResponseWriter, req *dns.Msg) {
w.WriteMsg(msg)
}
func (e *sthomeSolver) addDNSAnswer(q dns.Question, msg *dns.Msg, req *dns.Msg) error {
func (e *SthomeSolver) addDNSAnswer(q dns.Question, msg *dns.Msg, req *dns.Msg) error {
switch q.Qtype {
// Always return loopback for any A query
case dns.TypeA:

View File

@ -15,11 +15,11 @@ const (
dnsUpdaterScript = "/mnt/stpool1/scripts/acme/updatedns.sh"
)
// localDNSProviderSolver implements the provider-specific logic needed to
// LocalDNSProviderSolver implements the provider-specific logic needed to
// 'present' an ACME challenge TXT record for your own DNS provider.
// To do so, it must implement the `github.com/cert-manager/cert-manager/pkg/acme/webhook.Solver`
// interface.
type localDNSProviderSolver struct {
type LocalDNSProviderSolver struct {
client kubernetes.Clientset
//client kubernetes.Interface
}
@ -30,7 +30,7 @@ type localDNSProviderSolver struct {
// solvers configured with the same Name() **so long as they do not co-exist
// within a single webhook deployment**.
// For example, `cloudflare` may be used as the name of a solver.
func (p *localDNSProviderSolver) Name() string {
func (p *LocalDNSProviderSolver) Name() string {
return providerName
}
@ -39,7 +39,7 @@ func (p *localDNSProviderSolver) Name() string {
// This method should tolerate being called multiple times with the same value.
// cert-manager itself will later perform a self check to ensure that the
// 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)
cfg, err := loadConfig(ch.Config)
if err != nil {
@ -71,7 +71,7 @@ func (loc *localDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error
// value provided on the ChallengeRequest should be cleaned up.
// This is in order to facilitate multiple DNS validations for the same domain
// concurrently.
func (s *localDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
func (s *LocalDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
// TODO: add code that deletes a record from the DNS provider's console
// shell command
@ -96,7 +96,7 @@ func (s *localDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
// provider accounts.
// The stopCh can be used to handle early termination of the webhook, in cases
// where a SIGTERM or similar signal is sent to the webhook process.
func (c *localDNSProviderSolver) Initialize(kubeClientConfig *rest.Config, stopCh <-chan struct{}) error {
func (c *LocalDNSProviderSolver) Initialize(kubeClientConfig *rest.Config, stopCh <-chan struct{}) error {
cl, err := kubernetes.NewForConfig(kubeClientConfig)
if err != nil {
return fmt.Errorf("failed to get kubernetes client: %w", err)

View File

@ -12,32 +12,32 @@ import (
"k8s.io/client-go/rest"
)
type sthomeSolver struct {
type SthomeSolver struct {
name string
server *dns.Server
txtRecords map[string]string
sync.RWMutex
}
func (e *sthomeSolver) Name() string {
func (e *SthomeSolver) Name() string {
return e.name
}
func (e *sthomeSolver) Present(ch *acme.ChallengeRequest) error {
func (e *SthomeSolver) Present(ch *acme.ChallengeRequest) error {
e.Lock()
e.txtRecords[ch.ResolvedFQDN] = ch.Key
e.Unlock()
return nil
}
func (e *sthomeSolver) CleanUp(ch *acme.ChallengeRequest) error {
func (e *SthomeSolver) CleanUp(ch *acme.ChallengeRequest) error {
e.Lock()
delete(e.txtRecords, ch.ResolvedFQDN)
e.Unlock()
return nil
}
func (e *sthomeSolver) Initialize(kubeClientConfig *rest.Config, stopCh <-chan struct{}) error {
func (e *SthomeSolver) Initialize(kubeClientConfig *rest.Config, stopCh <-chan struct{}) error {
go func(done <-chan struct{}) {
<-done
if err := e.server.Shutdown(); err != nil {
@ -54,7 +54,7 @@ func (e *sthomeSolver) Initialize(kubeClientConfig *rest.Config, stopCh <-chan s
}
func New(port string) webhook.Solver {
e := &sthomeSolver{
e := &SthomeSolver{
name: "sthome",
txtRecords: make(map[string]string),
}

View File

@ -1,3 +1,6 @@
// private repo workaround
// Will use this file and remove same content from main.go when github repo is made public
package sthome
import (
@ -21,3 +24,5 @@ func loadConfig(cfgJSON *extapi.JSON) (localDNSProviderConfig, error) {
return cfg, nil
}
// end of private repo workaround