|
|
|
@ -246,44 +246,108 @@ def split_url(url: str) -> dict:
|
|
|
|
|
|
|
|
|
|
# Entry point to program
|
|
|
|
|
def main() -> int:
|
|
|
|
|
description = """Manage DNS records with knot dns rest api:
|
|
|
|
|
* https://gitlab.nic.cz/knot/knot-dns-rest"""
|
|
|
|
|
|
|
|
|
|
epilog = """
|
|
|
|
|
The Domain Name System specifies a database of information
|
|
|
|
|
elements for network resources. The types of information
|
|
|
|
|
elements are categorized and organized with a list of DNS
|
|
|
|
|
record types, the resource records (RRs). Each record has a
|
|
|
|
|
name, a type, an expiration time (time to live), and
|
|
|
|
|
type-specific data.
|
|
|
|
|
|
|
|
|
|
The following is a list of terms used in this program:
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
| Vocabulary | Description |
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
| zone | A DNS zone is a specific portion of the DNS |
|
|
|
|
|
| | namespace in the Domain Name System (DNS), |
|
|
|
|
|
| | which a specific organization or administrator |
|
|
|
|
|
| | manages. |
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
| name | In the Internet, a domain name is a string that |
|
|
|
|
|
| | identifies a realm of administrative autonomy, |
|
|
|
|
|
| | authority or control. Domain names are often |
|
|
|
|
|
| | used to identify services provided through the |
|
|
|
|
|
| | Internet, such as websites, email services and |
|
|
|
|
|
| | more. |
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
| rtype | A record type indicates the format of the data |
|
|
|
|
|
| | and it gives a hint of its intended use. For |
|
|
|
|
|
| | example, the A record is used to translate from |
|
|
|
|
|
| | a domain name to an IPv4 address, the NS record |
|
|
|
|
|
| | lists which name servers can answer lookups on |
|
|
|
|
|
| | a DNS zone, and the MX record specifies the |
|
|
|
|
|
| | mail server used to handle mail for a domain |
|
|
|
|
|
| | specified in an e-mail address. |
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
| data | A records data is of type-specific relevance, |
|
|
|
|
|
| | such as the IP address for address records, or |
|
|
|
|
|
| | the priority and hostname for MX records. |
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
This information was compiled from Wikipedia:
|
|
|
|
|
* https://en.wikipedia.org/wiki/DNS_zone
|
|
|
|
|
* https://en.wikipedia.org/wiki/Domain_Name_System
|
|
|
|
|
* https://en.wikipedia.org/wiki/Zone_file
|
|
|
|
|
"""
|
|
|
|
|
# Grab user input
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
parser = argparse.ArgumentParser(description=description, epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
|
|
|
parser.add_argument("--json", action=argparse.BooleanOptionalAction)
|
|
|
|
|
subparsers = parser.add_subparsers(dest="command")
|
|
|
|
|
addcmd = subparsers.add_parser("add")
|
|
|
|
|
|
|
|
|
|
add_description = "Add a new record to the zone."
|
|
|
|
|
addcmd = subparsers.add_parser("add", description=add_description)
|
|
|
|
|
addcmd.add_argument("-d", "--data", required=True)
|
|
|
|
|
addcmd.add_argument("-n", "--name", required=True)
|
|
|
|
|
addcmd.add_argument("-r", "--rtype", required=True)
|
|
|
|
|
addcmd.add_argument("-t", "--ttl")
|
|
|
|
|
addcmd.add_argument("-z", "--zone", required=True)
|
|
|
|
|
|
|
|
|
|
completecmd = subparsers.add_parser("completion")
|
|
|
|
|
complete_description = "Generate shell completion script."
|
|
|
|
|
completecmd = subparsers.add_parser("completion", description=complete_description)
|
|
|
|
|
completecmd.add_argument("-s", "--shell")
|
|
|
|
|
|
|
|
|
|
configcmd = subparsers.add_parser("config")
|
|
|
|
|
config_description = "Configure access to knot-dns-rest-api."
|
|
|
|
|
configcmd = subparsers.add_parser("config", description=config_description)
|
|
|
|
|
configcmd.add_argument("-b", "--baseurl")
|
|
|
|
|
configcmd.add_argument("-c", "--context")
|
|
|
|
|
configcmd.add_argument("-p", "--password")
|
|
|
|
|
configcmd.add_argument("-u", "--username")
|
|
|
|
|
|
|
|
|
|
deletecmd = subparsers.add_parser("delete")
|
|
|
|
|
delete_description = "Delete a record from the zone."
|
|
|
|
|
deletecmd = subparsers.add_parser("delete", description=delete_description)
|
|
|
|
|
deletecmd.add_argument("-d", "--data")
|
|
|
|
|
deletecmd.add_argument("-n", "--name")
|
|
|
|
|
deletecmd.add_argument("-r", "--rtype")
|
|
|
|
|
deletecmd.add_argument("-z", "--zone", required=True)
|
|
|
|
|
|
|
|
|
|
listcmd = subparsers.add_parser("list")
|
|
|
|
|
list_description = "List records in the zone."
|
|
|
|
|
listcmd = subparsers.add_parser("list", description=list_description)
|
|
|
|
|
listcmd.add_argument("-d", "--data")
|
|
|
|
|
listcmd.add_argument("-n", "--name")
|
|
|
|
|
listcmd.add_argument("-r", "--rtype")
|
|
|
|
|
listcmd.add_argument("-z", "--zone", required=True)
|
|
|
|
|
|
|
|
|
|
updatecmd = subparsers.add_parser("update")
|
|
|
|
|
update_description = "Update a record in the zone. The record must exist in the zone.\n"
|
|
|
|
|
update_description += "In this case --data, --name, --rtype and --ttl switches are used\n"
|
|
|
|
|
update_description += "for searching for the appropriate record, while the --argument\n"
|
|
|
|
|
update_description += "switches are used for updating the record."
|
|
|
|
|
update_epilog = """Available arguments are:
|
|
|
|
|
data: New record data.
|
|
|
|
|
name: New record domain name.
|
|
|
|
|
rtype: New record type.
|
|
|
|
|
ttl: New record time to live (TTL)."""
|
|
|
|
|
updatecmd = subparsers.add_parser("update", description=update_description, epilog=update_epilog, formatter_class=argparse.RawDescriptionHelpFormatter )
|
|
|
|
|
updatecmd.add_argument(
|
|
|
|
|
"-a",
|
|
|
|
|
"--argument",
|
|
|
|
|
nargs="*",
|
|
|
|
|
help="Specify key - value pairs to be updated: name=dns1.example.com.",
|
|
|
|
|
action="append",
|
|
|
|
|
metavar="KEY=VALUE",
|
|
|
|
|
help=
|
|
|
|
|
"Specify key - value pairs to be updated: name=dns1.example.com. or data=127.0.0.1 for example. --argument can be repeated",
|
|
|
|
|
required=True,
|
|
|
|
|
)
|
|
|
|
|
updatecmd.add_argument("-d", "--data", required=True)
|
|
|
|
@ -306,7 +370,8 @@ def main() -> int:
|
|
|
|
|
mkdir(config_basepath)
|
|
|
|
|
|
|
|
|
|
if args.command == "config":
|
|
|
|
|
run_config(config_filename, args.context, args.baseurl, args.username, args.password)
|
|
|
|
|
run_config(config_filename, args.context, args.baseurl, args.username,
|
|
|
|
|
args.password)
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
if not isfile(config_filename):
|
|
|
|
|