This should work
This commit is contained in:
parent
5aa072deb2
commit
9a7e0ef027
38
main.go
38
main.go
@ -5,12 +5,14 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
extapi "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
|
||||
"github.com/cert-manager/webhook-freedns/freedns"
|
||||
"github.com/jetstack/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
|
||||
"github.com/jetstack/cert-manager/pkg/acme/webhook/cmd"
|
||||
)
|
||||
@ -43,7 +45,8 @@ type customDNSProviderSolver struct {
|
||||
// 3. uncomment the relevant code in the Initialize method below
|
||||
// 4. ensure your webhook's service account has the required RBAC role
|
||||
// assigned to it for interacting with the Kubernetes APIs you need.
|
||||
client *kubernetes.Clientset
|
||||
client *kubernetes.Clientset
|
||||
freedns *freedns.FreeDNS
|
||||
}
|
||||
|
||||
// customDNSProviderConfig is a structure that is used to decode into when
|
||||
@ -68,7 +71,6 @@ type customDNSProviderConfig struct {
|
||||
|
||||
//Email string `json:"email"`
|
||||
SecretRef string `json:"secretName"`
|
||||
Domain string `json:"domain"`
|
||||
//APIKeySecretRef v1.SecretKeySelector `json:"apiKeySecretRef"`
|
||||
}
|
||||
|
||||
@ -102,9 +104,22 @@ func (c *customDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
|
||||
username := string(secretObj.Data["username"])
|
||||
password := string(secretObj.Data["password"])
|
||||
|
||||
fmt.Printf("Domain: %s, Auth: %s %s\n", cfg.Domain, username, password)
|
||||
freedns := freedns.FreeDNS{}
|
||||
err = freedns.Login(username, password)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: add code that sets a record in the DNS provider's console
|
||||
err = freedns.SelectDomain(ch.DNSName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_zone := strings.TrimRight(ch.ResolvedZone, ch.DNSName)
|
||||
_key := "\"" + ch.Key + "\""
|
||||
freedns.AddRecord("TXT", _zone, _key, true, "")
|
||||
|
||||
c.freedns = &freedns
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -115,7 +130,20 @@ func (c *customDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
|
||||
// This is in order to facilitate multiple DNS validations for the same domain
|
||||
// concurrently.
|
||||
func (c *customDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
|
||||
// TODO: add code that deletes a record from the DNS provider's console
|
||||
_zone := strings.TrimRight(ch.ResolvedZone, ch.DNSName)
|
||||
_key := "\"" + ch.Key + "\""
|
||||
_id, err := c.freedns.FindRecord(_zone, "TXT", _key)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _id != "" {
|
||||
err = c.freedns.DeleteRecord(_id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
1
testdata/freedns-solver/config.json
vendored
1
testdata/freedns-solver/config.json
vendored
@ -1,4 +1,3 @@
|
||||
{
|
||||
"secretName": "freedns-auth"
|
||||
, "domain": "example.com"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user