Skip to content

Commit

Permalink
Only delete a record by type and name, not only name.
Browse files Browse the repository at this point in the history
  • Loading branch information
kiarn committed May 4, 2023
1 parent 0538d59 commit 47fd91e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions plugins/dns_api/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def add_record(self, record):
def update_record(self, record):
return self.api.update_record(self.fqdn, record)

def delete_record(self, name):
return self.api.delete_record(self.fqdn, name)
def delete_record(self, rtype, name):
return self.api.delete_record(self.fqdn, rtype, name)


class DomainManager:
Expand Down
10 changes: 6 additions & 4 deletions plugins/dns_api/providers/gandi.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,22 @@ def update_record(self, fqdn, record):
except Exception as e:
logging.error(e)

def delete_record(self, fqdn, name):
def delete_record(self, fqdn, rtype, name):
"""
Delete a record from a given domain.
:param fqdn: the domain, like example.com
:type fqdn: basestring
:param record: the record name, like test (to delete the entry test.example.com)
:type record: Record object
:param rtype: type of the DNS entry, like CNAME or AAAA
:type rtype: basestring
:param name: the record name, like test (to delete the entry test.example.com)
:type name: basestring
:return: status of the request and message
:rtype: tuple
"""

try:
resp = self._req('delete', apiurl=f"/{fqdn}/records/{name}")
resp = self._req('delete', apiurl=f"/{fqdn}/records/{name}/{rtype}")
if resp.content:
messages = json.loads(resp.content)
else:
Expand Down
6 changes: 3 additions & 3 deletions plugins/dns_api/resources/js/controllers/index.controller.es
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ angular.module('ajenti.dns_api').controller('DnsAPIIndexController', function($s
$scope.detailsVisible = false;
};

$scope.delete = (name) => {
$scope.delete = (record) => {
messagebox.show({
text: gettext(`Really delete the entry ${name}?`),
text: gettext(`Really delete the entry "${record.name} ${record.type} ${record.values}"?`),
positive: gettext('Delete'),
negative: gettext('Cancel')
}).then(() => {
$http.delete(`/api/dns_api/domain/${$scope.active_domain}/records/${name}`).then((resp) => {
$http.delete(`/api/dns_api/domain/${$scope.active_domain}/records/${record.type}/${record.name}`).then((resp) => {
code = resp.data[0];
msg = resp.data[1];
if (code >= 200 && code < 300) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/dns_api/resources/partial/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h2>{{provider}}</h2>
</button>
</td>
<td>
<button class="btn btn-default" ng:click="delete(record.name)">
<button class="btn btn-default" ng:click="delete(record)">
<i class="fas fa-trash"></i>
</button>
</td>
Expand Down
6 changes: 3 additions & 3 deletions plugins/dns_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def handle_api_dns_put_record(self, http_context, fqdn, name):
)
return self.mgr.domains[fqdn].update_record(record)

@delete(r'/api/dns_api/domain/(?P<fqdn>[\w\.]+)/records/(?P<name>.*)')
@delete(r'/api/dns_api/domain/(?P<fqdn>[\w\.]+)/records/(?P<rtype>[A-Z]*)/(?P<name>.*)')
@endpoint(api=True)
def handle_api_dns_delete_record(self, http_context, fqdn, name):
return self.mgr.domains[fqdn].delete_record(name)
def handle_api_dns_delete_record(self, http_context, fqdn, rtype, name):
return self.mgr.domains[fqdn].delete_record(rtype, name)

0 comments on commit 47fd91e

Please sign in to comment.