Do not use ch.DNSName
This commit is contained in:
parent
9a7e0ef027
commit
fb99ace026
@ -34,6 +34,12 @@ const URI_DELETE_RECORD = "https://freedns.afraid.org/subdomain/delete2.php?data
|
||||
|
||||
// const URI_LOGIN string = "http://127.0.0.1:1234/"
|
||||
|
||||
func GetDomainFromZone(Zone string) string {
|
||||
_segs := strings.Split(Zone, ".")
|
||||
_segs = _segs[len(_segs)-2:]
|
||||
return strings.Join(_segs, ".")
|
||||
}
|
||||
|
||||
func _HttpRequest(method string, url string, PostData url.Values, ExCookie *http.Cookie) (*http.Response, string, error) {
|
||||
client := http.Client{
|
||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||
|
24
main.go
24
main.go
@ -104,22 +104,23 @@ func (c *customDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
|
||||
username := string(secretObj.Data["username"])
|
||||
password := string(secretObj.Data["password"])
|
||||
|
||||
freedns := freedns.FreeDNS{}
|
||||
err = freedns.Login(username, password)
|
||||
dnsObj := freedns.FreeDNS{}
|
||||
err = dnsObj.Login(username, password)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = freedns.SelectDomain(ch.DNSName)
|
||||
domainName := freedns.GetDomainFromZone(ch.ResolvedZone)
|
||||
err = dnsObj.SelectDomain(domainName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_zone := strings.TrimRight(ch.ResolvedZone, ch.DNSName)
|
||||
_zone := strings.TrimRight(ch.ResolvedZone, domainName)
|
||||
_key := "\"" + ch.Key + "\""
|
||||
freedns.AddRecord("TXT", _zone, _key, true, "")
|
||||
dnsObj.AddRecord("TXT", _zone, _key, true, "")
|
||||
|
||||
c.freedns = &freedns
|
||||
c.freedns = &dnsObj
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -130,13 +131,9 @@ 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 {
|
||||
_zone := strings.TrimRight(ch.ResolvedZone, ch.DNSName)
|
||||
_key := "\"" + ch.Key + "\""
|
||||
_id, err := c.freedns.FindRecord(_zone, "TXT", _key)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_key := "\"" + ch.Key + "\""
|
||||
_id, err := c.freedns.FindRecord(ch.ResolvedZone, "TXT", _key)
|
||||
|
||||
if _id != "" {
|
||||
err = c.freedns.DeleteRecord(_id)
|
||||
@ -144,7 +141,8 @@ func (c *customDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
return c.freedns.Logout()
|
||||
}
|
||||
|
||||
// Initialize will be called when the webhook first starts.
|
||||
|
Loading…
Reference in New Issue
Block a user