简体   繁体   English

删除记录 Libcloud (GoDaddy api)

[英]Delete record Libcloud (GoDaddy api)

我尝试为 Record delate-record实现 delete 方法,但这是我第一次使用 python 和这个 api。

The GoDaddy API doesn't have a delete record method, so this functionality is not exposed in the driver. GoDaddy API 没有删除记录方法,因此此功能未在驱动程序中公开。 https://developer.godaddy.com/doc#!/_v1_domains/recordReplace https://developer.godaddy.com/doc#!/_v1_domains/recordReplace

The driver could offer the 'replace records in zone' method, which would allow you to fetch the current list of records, and then set the new list minus the record you want to remove.驱动程序可以提供“替换区域中的记录”方法,这将允许您获取当前的记录列表,然后设置新列表减去要删除的记录。 But that feature is not implemented and quite risky.但该功能尚未实现,而且风险很大。

First, Send a GET request to https://api.godaddy.com/v1/domains/{DOMAIN}/records首先,向https://api.godaddy.com/v1/domains/{DOMAIN}/records发送 GET 请求

Then, Enumerate over all records of API Response (JSON Array) and prepare new data by removing the one that needs to be deleted.然后,枚举 API Response (JSON Array) 的所有记录,并通过删除需要删除的记录来准备新数据。

API Response (SAMPLE) API 响应(示例)

[
    {
        "data": "192.168.1.1",
        "name": "@",
        "ttl": 600,
        "type": "A"
    },
    {
        "data": "ns1.example.com",
        "name": "@",
        "ttl": 3600,
        "type": "NS"
    },
    {
        "data": "@",
        "name": "www",
        "ttl": 3600,
        "type": "CNAME"
    },
    {
        "data": "mail.example.com",
        "name": "@",
        "ttl": 3600,
        "priority": 1,
        "type": "MX"
    }
]

New Data (After deleting record) (SAMPLE)新数据(删除记录后)(SAMPLE)

[
    {
        "data": "192.168.1.1",
        "name": "@",
        "ttl": 600,
        "type": "A"
    },
    {
        "data": "ns1.example.com",
        "name": "@",
        "ttl": 3600,
        "type": "NS"
    },
    {
        "data": "@",
        "name": "www",
        "ttl": 3600,
        "type": "CNAME"
    }
]

Now, Send a PUT request to https://api.godaddy.com/v1/domains/{DOMAIN}/records with new data.现在,使用新数据向https://api.godaddy.com/v1/domains/{DOMAIN}/records发送 PUT 请求。

The most important thing is how you identify the records in above array which needs to be deleted.最重要的是如何识别上述数组中需要删除的记录。 This would not be a difficult task, assuming you have good programming skills.假设您具有良好的编程技能,这将不是一项艰巨的任务。

I managed to worked around it in kind of a hacky - we had bunch of records we wanted to delete, doing it manually seemed weird so I added a Javascript into the Chrome Developer Console, running on an authenticated session from the DNS manage page:我设法解决了这个问题 - 我们有一堆想要删除的记录,手动操作似乎很奇怪,所以我在 Chrome 开发者控制台中添加了一个 Javascript,在 DNS 管理页面的经过身份验证的会话上运行:

function deleteGoDaddyRecords(recordId) {
        $.ajax({
        url: 'https://dcc.godaddy.com/api/v3/domains/<YOUR-DOMAIN.com>/records?recordId='+recordId,
        type: 'DELETE',
        success: function(result) {
            console.log(result)
        }
    });
}

which let me use the same call the UI is calling when you ask to delete a record.当您要求删除记录时,这让我可以使用 UI 正在调用的相同调用。

the only thing you need to provide is the AttributeUid which is not available with the public API, but it is in the front-end API:您唯一需要提供的是 AttributeUid,它在公共 API 中不可用,但它在前端 API 中:

https://dcc.godaddy.com/api/v2/domains/runahr.com/records https://dcc.godaddy.com/api/v2/domains/runahr.com/records

So I managed to create a script that will generate bunch of所以我设法创建了一个脚本来生成一堆

deleteGoDaddyRecords('<RECORD-UUID>');
deleteGoDaddyRecords('<RECORD-UUID>');

copy & paste the generated script into the Developers Console and that solved it for now.将生成的脚本复制并粘贴到开发人员控制台中,暂时解决了这个问题。

I hope GoDaddy will add a public DELETE endpoint to their API in the future :)我希望 GoDaddy 将来会在他们的 API 中添加一个公共 DELETE 端点:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM