Properly implements logging

This commit is contained in:
2024-11-01 19:47:42 +00:00
parent d22266fd9a
commit 2da56a0aaf
4 changed files with 15 additions and 19 deletions
@@ -26,6 +26,7 @@ spec:
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }} imagePullPolicy: {{ .Values.image.pullPolicy }}
args: args:
- --v=2
- --tls-cert-file=/tls/tls.crt - --tls-cert-file=/tls/tls.crt
- --tls-private-key-file=/tls/tls.key - --tls-private-key-file=/tls/tls.key
env: env:
+1 -1
View File
@@ -14,7 +14,7 @@ certManager:
image: image:
repository: penguinade/cert-manager-webhook-freedns repository: penguinade/cert-manager-webhook-freedns
tag: 2024.10.31.04 tag: 2024.11.02.04
pullPolicy: IfNotPresent pullPolicy: IfNotPresent
nameOverride: "" nameOverride: ""
+11 -15
View File
@@ -35,16 +35,6 @@ const URI_SUBDOMAIN_EDIT = "https://freedns.afraid.org/subdomain/edit.php?data_i
const URI_LOGOUT = "https://freedns.afraid.org/logout/" const URI_LOGOUT = "https://freedns.afraid.org/logout/"
const URI_DELETE_RECORD = "https://freedns.afraid.org/subdomain/delete2.php?data_id[]=%s&submit=delete%%20selected" const URI_DELETE_RECORD = "https://freedns.afraid.org/subdomain/delete2.php?data_id[]=%s&submit=delete%%20selected"
func LogInfo(Mesg string) {
//fmt.Println(Mesg)
logf.V(logf.InfoLevel).Info(Mesg)
}
func LogDebug(Mesg string) {
//fmt.Println(Mesg)
logf.V(logf.DebugLevel).Info(Mesg)
}
func GetDomainFromZone(Zone string) string { func GetDomainFromZone(Zone string) string {
_segs := strings.Split(strings.TrimSuffix(Zone, "."), ".") _segs := strings.Split(strings.TrimSuffix(Zone, "."), ".")
_segs = _segs[len(_segs)-2:] _segs = _segs[len(_segs)-2:]
@@ -165,7 +155,7 @@ loop:
break loop break loop
case html.TextToken: case html.TextToken:
if inBold && strings.TrimSpace(htmlTokens.Token().Data) == DomainName { if inBold && strings.TrimSpace(htmlTokens.Token().Data) == DomainName {
LogInfo("Found " + DomainName + ", looking for domain id") logf.V(logf.InfoLevel).Info(fmt.Sprintf("Found HTMLTextNode that contains \"%s\", try looking for domain id", DomainName))
lookForA = true lookForA = true
} }
// The [Manage] anchor is next to the bold tag // The [Manage] anchor is next to the bold tag
@@ -180,7 +170,7 @@ loop:
_href := string(attrValue) _href := string(attrValue)
if string(attrKey) == "href" && strings.HasPrefix(_href, "/subdomain/?limit=") { if string(attrKey) == "href" && strings.HasPrefix(_href, "/subdomain/?limit=") {
dnsObj.DomainId = strings.TrimPrefix(_href, "/subdomain/?limit=") dnsObj.DomainId = strings.TrimPrefix(_href, "/subdomain/?limit=")
LogDebug(fmt.Sprintf("Domain id for \"%s\" is %s\n", DomainName, dnsObj.DomainId)) logf.V(logf.InfoLevel).Info(fmt.Sprintf("Domain id for \"%s\" is %s", DomainName, dnsObj.DomainId))
break loop break loop
} }
if !moreAttr { if !moreAttr {
@@ -202,6 +192,9 @@ func (dnsObj *FreeDNS) AddRecord(RecordType string, Subdomain string, Address st
if dnsObj.DomainId == "" { if dnsObj.DomainId == "" {
return errors.New("No domain selected") return errors.New("No domain selected")
} }
logf.V(logf.InfoLevel).Info(fmt.Sprintf("Adding %s Record: %s %s", RecordType, Subdomain, Address))
recordData := url.Values{} recordData := url.Values{}
recordData.Set("type", RecordType) recordData.Set("type", RecordType)
recordData.Set("domain_id", dnsObj.DomainId) recordData.Set("domain_id", dnsObj.DomainId)
@@ -221,7 +214,7 @@ func (dnsObj *FreeDNS) AddRecord(RecordType string, Subdomain string, Address st
// Record already exists, treat this as success // Record already exists, treat this as success
if strings.Contains(respStr, "already have another already existent") { if strings.Contains(respStr, "already have another already existent") {
LogInfo("Record already exists") logf.V(logf.InfoLevel).Info("Record already exists")
return nil return nil
} }
@@ -281,7 +274,7 @@ func (dnsObj *FreeDNS) AddRecord(RecordType string, Subdomain string, Address st
} }
if strings.HasPrefix(_Location.Path, "/zc.php") { if strings.HasPrefix(_Location.Path, "/zc.php") {
LogDebug("Error on AddRecord: Cookie expired") logf.V(logf.DebugLevel).Info("Error on AddRecord: Cookie expired")
return errors.New("dns_cookie maybe expired") return errors.New("dns_cookie maybe expired")
} }
@@ -289,6 +282,9 @@ func (dnsObj *FreeDNS) AddRecord(RecordType string, Subdomain string, Address st
} }
func (dnsObj *FreeDNS) DeleteRecord(RecordId string) error { func (dnsObj *FreeDNS) DeleteRecord(RecordId string) error {
logf.V(logf.InfoLevel).Info(fmt.Sprintf("(id=%s) Removing Record", RecordId))
resp, _, err := _HttpRequest("GET", fmt.Sprintf(URI_DELETE_RECORD, RecordId), nil, dnsObj.AuthCookie) resp, _, err := _HttpRequest("GET", fmt.Sprintf(URI_DELETE_RECORD, RecordId), nil, dnsObj.AuthCookie)
if err != nil { if err != nil {
return err return err
@@ -391,7 +387,7 @@ loop:
// Begin deep search for truncated records // Begin deep search for truncated records
htmlAddr := strings.ReplaceAll(html.EscapeString(Address), """, """) htmlAddr := strings.ReplaceAll(html.EscapeString(Address), """, """)
for _, RecordId := range DeepSearchCandidates { for _, RecordId := range DeepSearchCandidates {
LogDebug("Searching in " + RecordId) logf.V(logf.DebugLevel).Info("Searching in " + RecordId)
_, respStr, err := _HttpRequest("GET", URI_SUBDOMAIN_EDIT+RecordId, nil, dnsObj.AuthCookie) _, respStr, err := _HttpRequest("GET", URI_SUBDOMAIN_EDIT+RecordId, nil, dnsObj.AuthCookie)
if err != nil { if err != nil {
continue continue
+2 -3
View File
@@ -12,6 +12,7 @@ import (
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
logf "github.com/cert-manager/cert-manager/pkg/logs"
"github.com/cert-manager/webhook-freedns/freedns" "github.com/cert-manager/webhook-freedns/freedns"
"github.com/cert-manager/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1" "github.com/cert-manager/cert-manager/pkg/acme/webhook/apis/acme/v1alpha1"
"github.com/cert-manager/cert-manager/pkg/acme/webhook/cmd" "github.com/cert-manager/cert-manager/pkg/acme/webhook/cmd"
@@ -121,8 +122,6 @@ func (c *customDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
_zone = strings.TrimRight(_zone, ".") _zone = strings.TrimRight(_zone, ".")
_key := "\"" + ch.Key + "\"" _key := "\"" + ch.Key + "\""
freedns.LogInfo(fmt.Sprintf("ADD %s %s", _zone, _key))
err = dnsObj.AddRecord("TXT", _zone, _key, false, "") err = dnsObj.AddRecord("TXT", _zone, _key, false, "")
if err != nil { if err != nil {
return err return err
@@ -150,7 +149,7 @@ func (c *customDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
_key := "\"" + ch.Key + "\"" _key := "\"" + ch.Key + "\""
_id, err := c.freedns.FindRecord(_addr, "TXT", _key) _id, err := c.freedns.FindRecord(_addr, "TXT", _key)
freedns.LogInfo(fmt.Sprintf("DEL %s %s", _addr, _key)) logf.V(logf.InfoLevel).Info(fmt.Sprintf("(id=%s) TXT Record: %s %s", _id, _addr, _key))
if _id != "" { if _id != "" {
err = c.freedns.DeleteRecord(_id) err = c.freedns.DeleteRecord(_id)