manitu api v1

This commit is contained in:
Simon Zeyer 2022-10-14 16:27:03 +02:00
parent 8fc6c4f7de
commit fd543c4855

26
main.go
View File

@ -97,6 +97,7 @@ type Entry struct {
Name string `json:"host"`
TTL int `json:"ttl"`
Type string `json:"type"`
ClassType string `json:"classtype"`
Value string `json:"value"`
ZoneID string `json:"zone"`
}
@ -139,17 +140,17 @@ func (c *manituDNSProviderSolver) Present(ch *v1alpha1.ChallengeRequest) error {
// Display Results
fmt.Println("response Status : ", resp.Status)
fmt.Println("response Headers : ", resp.Header)
fmt.Println("response Body : ", respBody.Zone.ZoneID)
fmt.Println("response Body : ", respBody.ZoneID)
// Create DNS
entry, err := json.Marshal(Entry{"", name, 300, "TXT", ch.Key, respBody.Zones[0].ZoneID})
entry, err := json.Marshal(Entry{name, 300, "TXT", "IN", ch.Key, respBody.ZoneID})
body := bytes.NewBuffer(entry)
// Create request
req, err = http.NewRequest("POST", "https://dnsapi.elutions-network.de/api/v1/records", body)
// Headers
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Auth-API-Token", cfg.APIKey)
req.Header.Add("Authorization", cfg.APIKey)
// Fetch Request
resp, err = client.Do(req)
@ -190,9 +191,9 @@ func (c *manituDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
client := &http.Client{}
// Create request
zReq, err := http.NewRequest("GET", "https://dnsapi.elutions-network.de/api/v1/zones?search_name="+zone, nil)
zReq, err := http.NewRequest("GET", "https://dnsapi.elutions-network.de/api/v1/zones/"+zone, nil)
// Headers
zReq.Header.Add("Auth-API-Token", cfg.APIKey)
zReq.Header.Add("Authorization", cfg.APIKey)
// Fetch Request
zResp, err := client.Do(zReq)
@ -201,19 +202,19 @@ func (c *manituDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
}
// Read Response Body
zRespBody := Zones{}
zRespBody := Zone{}
json.NewDecoder(zResp.Body).Decode(&zRespBody)
// Display Results
fmt.Println("response Status : ", zResp.Status)
fmt.Println("response Headers : ", zResp.Header)
fmt.Println("response Body : ", zRespBody.Zones[0].ZoneID)
fmt.Println("response Body : ", zRespBody.ZoneID)
fmt.Println("response Body : ", name)
// Create request
eReq, err := http.NewRequest("GET", "https://dnsapi.elutions-network.de/api/v1/records?zone_id="+zRespBody.Zones[0].ZoneID, nil)
eReq, err := http.NewRequest("GET", "https://dnsapi.elutions-network.de/api/v1/zones/"+zRespBody.ZoneID+"/records", nil)
// Headers
eReq.Header.Add("Auth-API-Token", cfg.APIKey)
eReq.Header.Add("Authorization", cfg.APIKey)
// Fetch Request
eResp, err := client.Do(eReq)
@ -226,6 +227,7 @@ func (c *manituDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
json.NewDecoder(eResp.Body).Decode(&eRespBody)
// Display Results
fmt.Println("response Status : ", eResp.Status)
fmt.Println("response Headers : ", eResp.Header)
fmt.Println("response Body : ", eRespBody)
@ -233,12 +235,12 @@ func (c *manituDNSProviderSolver) CleanUp(ch *v1alpha1.ChallengeRequest) error {
for _, e := range eRespBody.Records {
if e.Type == "TXT" && e.Name == name && e.Value == ch.Key {
fmt.Println("Found DOMAIN: ", e)
// Delete Record (DELETE https://dnsapi.elutions-network.de/api/v1/records/1)
// Delete Record
// Create request
req, err := http.NewRequest("DELETE", "https://dnsapi.elutions-network.de/api/v1/records/"+e.ID, nil)
req, err := http.NewRequest("DELETE", "https://dnsapi.elutions-network.de/api/v1/zones/"+zRespBody.ZoneID+"/records?host="+e.Name+"&value="+e.Value+"&type="+e.Type, nil)
// Headers
req.Header.Add("Auth-API-Token", cfg.APIKey)
req.Header.Add("Authorization", cfg.APIKey)
// Fetch Request
resp, err := client.Do(req)