Capitalised functions/structs for export
This commit is contained in:
parent
ca6f5facba
commit
5c1530e21f
2
go.mod
2
go.mod
@ -5,6 +5,8 @@ go 1.21
|
|||||||
toolchain go1.22.1
|
toolchain go1.22.1
|
||||||
|
|
||||||
require (
|
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/cert-manager/cert-manager v1.14.4
|
||||||
github.com/miekg/dns v1.1.58
|
github.com/miekg/dns v1.1.58
|
||||||
github.com/stretchr/testify v1.8.4
|
github.com/stretchr/testify v1.8.4
|
||||||
|
|||||||
3
main.go
3
main.go
@ -4,6 +4,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"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"
|
"github.com/stuurmcp/cert-manager-webhook-sthome/sthome"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,6 +15,6 @@ func main() {
|
|||||||
panic("GROUP_NAME must be specified")
|
panic("GROUP_NAME must be specified")
|
||||||
}
|
}
|
||||||
cmd.RunWebhookServer(GroupName,
|
cmd.RunWebhookServer(GroupName,
|
||||||
&sthome.localDNSProviderSolver{},
|
&sthome.LocalDNSProviderSolver{},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/miekg/dns"
|
"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 := new(dns.Msg)
|
||||||
msg.SetReply(req)
|
msg.SetReply(req)
|
||||||
switch req.Opcode {
|
switch req.Opcode {
|
||||||
@ -22,7 +22,7 @@ func (e *sthomeSolver) handleDNSRequest(w dns.ResponseWriter, req *dns.Msg) {
|
|||||||
w.WriteMsg(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 {
|
switch q.Qtype {
|
||||||
// Always return loopback for any A query
|
// Always return loopback for any A query
|
||||||
case dns.TypeA:
|
case dns.TypeA:
|
||||||
|
|||||||
@ -15,11 +15,11 @@ const (
|
|||||||
dnsUpdaterScript = "/mnt/stpool1/scripts/acme/updatedns.sh"
|
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.
|
// '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`
|
// To do so, it must implement the `github.com/cert-manager/cert-manager/pkg/acme/webhook.Solver`
|
||||||
// interface.
|
// interface.
|
||||||
type localDNSProviderSolver struct {
|
type LocalDNSProviderSolver struct {
|
||||||
client kubernetes.Clientset
|
client kubernetes.Clientset
|
||||||
//client kubernetes.Interface
|
//client kubernetes.Interface
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ type localDNSProviderSolver struct {
|
|||||||
// solvers configured with the same Name() **so long as they do not co-exist
|
// solvers configured with the same Name() **so long as they do not co-exist
|
||||||
// within a single webhook deployment**.
|
// within a single webhook deployment**.
|
||||||
// For example, `cloudflare` may be used as the name of a solver.
|
// For example, `cloudflare` may be used as the name of a solver.
|
||||||
func (p *localDNSProviderSolver) Name() string {
|
func (p *LocalDNSProviderSolver) Name() string {
|
||||||
return providerName
|
return providerName
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ func (p *localDNSProviderSolver) Name() string {
|
|||||||
// This method should tolerate being called multiple times with the same value.
|
// 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
|
// 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 {
|
||||||
@ -71,7 +71,7 @@ func (loc *localDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error
|
|||||||
// value provided on the ChallengeRequest should be cleaned up.
|
// value provided on the ChallengeRequest should be cleaned up.
|
||||||
// This is in order to facilitate multiple DNS validations for the same domain
|
// This is in order to facilitate multiple DNS validations for the same domain
|
||||||
// concurrently.
|
// 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
|
// TODO: add code that deletes a record from the DNS provider's console
|
||||||
|
|
||||||
// shell command
|
// shell command
|
||||||
@ -96,7 +96,7 @@ func (s *localDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
|
|||||||
// provider accounts.
|
// provider accounts.
|
||||||
// The stopCh can be used to handle early termination of the webhook, in cases
|
// 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.
|
// 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)
|
cl, err := kubernetes.NewForConfig(kubeClientConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get kubernetes client: %w", err)
|
return fmt.Errorf("failed to get kubernetes client: %w", err)
|
||||||
|
|||||||
@ -12,32 +12,32 @@ import (
|
|||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
type sthomeSolver struct {
|
type SthomeSolver struct {
|
||||||
name string
|
name string
|
||||||
server *dns.Server
|
server *dns.Server
|
||||||
txtRecords map[string]string
|
txtRecords map[string]string
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *sthomeSolver) Name() string {
|
func (e *SthomeSolver) Name() string {
|
||||||
return e.name
|
return e.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *sthomeSolver) Present(ch *acme.ChallengeRequest) error {
|
func (e *SthomeSolver) Present(ch *acme.ChallengeRequest) error {
|
||||||
e.Lock()
|
e.Lock()
|
||||||
e.txtRecords[ch.ResolvedFQDN] = ch.Key
|
e.txtRecords[ch.ResolvedFQDN] = ch.Key
|
||||||
e.Unlock()
|
e.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *sthomeSolver) CleanUp(ch *acme.ChallengeRequest) error {
|
func (e *SthomeSolver) CleanUp(ch *acme.ChallengeRequest) error {
|
||||||
e.Lock()
|
e.Lock()
|
||||||
delete(e.txtRecords, ch.ResolvedFQDN)
|
delete(e.txtRecords, ch.ResolvedFQDN)
|
||||||
e.Unlock()
|
e.Unlock()
|
||||||
return nil
|
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{}) {
|
go func(done <-chan struct{}) {
|
||||||
<-done
|
<-done
|
||||||
if err := e.server.Shutdown(); err != nil {
|
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 {
|
func New(port string) webhook.Solver {
|
||||||
e := &sthomeSolver{
|
e := &SthomeSolver{
|
||||||
name: "sthome",
|
name: "sthome",
|
||||||
txtRecords: make(map[string]string),
|
txtRecords: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
package sthome
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -21,3 +24,5 @@ func loadConfig(cfgJSON *extapi.JSON) (localDNSProviderConfig, error) {
|
|||||||
|
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// end of private repo workaround
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user