mirror of
https://github.com/cert-manager/webhook-example.git
synced 2025-07-02 23:05:48 +02:00
add cleanup logic
This commit is contained in:
parent
6b9c14cc74
commit
962afa45e0
1 changed files with 59 additions and 1 deletions
60
main.go
60
main.go
|
@ -153,7 +153,65 @@ func (c *bluecatDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error
|
||||||
// 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 (c *bluecatDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
|
func (c *bluecatDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
|
||||||
// TODO: add code that deletes a record from the DNS provider's console
|
cfg, err := loadConfig(ch.Config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
source := util.UnFqdn(ch.ResolvedFQDN)
|
||||||
|
|
||||||
|
err = bluecatLogin(cfg.ServerURL, cfg.Username, cfg.Password, cfg.ConfigName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
viewID, err := bluecatLookupViewID(cfg.ConfigName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
parentID, name, err := bluecatLookupParentZoneID(viewID, source)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
queryArgs := map[string]string{
|
||||||
|
"parentId": strconv.FormatUint(uint64(parentID), 10),
|
||||||
|
"name": name,
|
||||||
|
"type": "TXTRecord",
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := bluecatSendRequest(http.MethodGet, "getEntityByName", nil, queryArgs)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
var txtRec entityResponse
|
||||||
|
err = json.NewDecoder(resp.Body).Decode(&txtRec)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("bluecat: %w", err)
|
||||||
|
}
|
||||||
|
queryArgs = map[string]string{
|
||||||
|
"objectId": strconv.FormatUint(uint64(txtRec.ID), 10),
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err = bluecatSendRequest(http.MethodDelete, http.MethodDelete, nil, queryArgs)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
err = bluecatDeploy(parentID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = bluecatLogout()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue