|
|
@ -53,12 +53,21 @@ local _parse_record = function(rec)
|
|
|
|
for _, v in ipairs(rec) do
|
|
|
|
for _, v in ipairs(rec) do
|
|
|
|
if v ~= nil and v ~= "" then
|
|
|
|
if v ~= nil and v ~= "" then
|
|
|
|
local key = v:match("%w+"):lower()
|
|
|
|
local key = v:match("%w+"):lower()
|
|
|
|
record[key] = v:gsub("%w+%:%s", "")
|
|
|
|
if vim.tbl_contains({ "zone", "rtype", "name", "data", "ttl" }, key) then
|
|
|
|
|
|
|
|
record[key] = v:gsub("%w+%:%s", "")
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return record
|
|
|
|
return record
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local _validate_record = function(record)
|
|
|
|
|
|
|
|
if record.zone == nil or record.rtype == nil or record.name == nil or record.data == nil then
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
local M = {}
|
|
|
|
M.add = function(_)
|
|
|
|
M.add = function(_)
|
|
|
|
local tempfile = vim.fn.tempname()
|
|
|
|
local tempfile = vim.fn.tempname()
|
|
|
@ -82,14 +91,18 @@ M.add = function(_)
|
|
|
|
callback = function(_)
|
|
|
|
callback = function(_)
|
|
|
|
local new = vim.api.nvim_buf_get_lines(buffer, 0, -1, false)
|
|
|
|
local new = vim.api.nvim_buf_get_lines(buffer, 0, -1, false)
|
|
|
|
local record = _parse_record(new)
|
|
|
|
local record = _parse_record(new)
|
|
|
|
local command = "knotctl add -z " .. record.zone ..
|
|
|
|
if _validate_record(record) then
|
|
|
|
" -t " .. record.ttl ..
|
|
|
|
local command = "knotctl add -z " .. record.zone ..
|
|
|
|
" -n " .. record.name ..
|
|
|
|
" -t " .. record.ttl ..
|
|
|
|
" -r " .. record.rtype ..
|
|
|
|
" -n " .. record.name ..
|
|
|
|
" -d " .. record.data
|
|
|
|
" -r " .. record.rtype ..
|
|
|
|
local choice = vim.fn.confirm("Create record?", "&Yes\n&No", 2)
|
|
|
|
" -d " .. record.data
|
|
|
|
if choice == 1 then
|
|
|
|
local choice = vim.fn.confirm("Create record?", "&Yes\n&No", 2)
|
|
|
|
log.info(vim.fn.system(command))
|
|
|
|
if choice == 1 then
|
|
|
|
|
|
|
|
log.info(vim.fn.system(command))
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
log.error("Invalid record")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -182,15 +195,19 @@ M.update = function(opts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if did_update then
|
|
|
|
if did_update then
|
|
|
|
local command = "knotctl update -z " .. cleanold.zone ..
|
|
|
|
if _validate_record(cleannew) and _validate_record(cleanold) then
|
|
|
|
" -t " .. cleanold.ttl ..
|
|
|
|
local command = "knotctl update -z " .. cleanold.zone ..
|
|
|
|
" -n " .. cleanold.name ..
|
|
|
|
" -t " .. cleanold.ttl ..
|
|
|
|
" -r " .. cleanold.rtype ..
|
|
|
|
" -n " .. cleanold.name ..
|
|
|
|
" -d " .. cleanold.data ..
|
|
|
|
" -r " .. cleanold.rtype ..
|
|
|
|
table.concat(updated, " ")
|
|
|
|
" -d " .. cleanold.data ..
|
|
|
|
local choice = vim.fn.confirm("Update record?", "&Yes\n&No", 2)
|
|
|
|
table.concat(updated, " ")
|
|
|
|
if choice == 1 then
|
|
|
|
local choice = vim.fn.confirm("Update record?", "&Yes\n&No", 2)
|
|
|
|
log.info(vim.fn.system(command))
|
|
|
|
if choice == 1 then
|
|
|
|
|
|
|
|
log.info(vim.fn.system(command))
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
log.error("Invalid record")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|