Skip to content

Commit

Permalink
Merge pull request #3 from mpdevilleres/replace-yaml-to-toml
Browse files Browse the repository at this point in the history
replace yaml to toml
  • Loading branch information
ivan-jedek committed Dec 18, 2023
2 parents 5de78b8 + 5a5c4c0 commit 49893ec
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This can be useful for:

## Installation

1) Install Python 3.10 or newer.
1) Install Python 3.11 or newer.
2) Install PyYAML:
```
pip3 install pyyaml
Expand All @@ -33,7 +33,7 @@ pip3 install pyyaml

## Running PolarDNS

Make sure you are using Python 3.10 or newer to run the PolarDNS server:
Make sure you are using Python 3.11 or newer to run the PolarDNS server:
```
python polardns.py
```
Expand Down
21 changes: 19 additions & 2 deletions polardns.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,33 @@
import time
import sys
import os
import yaml
import tomllib

version = "1.0"
stamp = str(time.time()).ljust(18, "0")
print("%s | PolarDNS %s server starting up" % (stamp, version))

################################

config = yaml.safe_load(open("polardns.yml"))
### PARSE CONFIGURATION
# note: this has some transformation as not to break the existing usage of config variable
# please update the usage to simplify this transformation in future iteration`
with open("polardns.toml", "rb") as f:
_config = tomllib.load(f)
config = {k:v for k,v in _config['main'].items() if k != 'known_servers'}

known_servers = {}
for line in _config['main']['known_servers'].split('\n'):
if not line:
continue
host, ip_address = line.split()
known_servers[host] = ip_address

config['known_servers'] = known_servers
debug = config['debug']

### END PARSE CONFIGURATION

globalttl = int(config['ttl'])
globalsleep = float(config['sleep'])

Expand Down
27 changes: 27 additions & 0 deletions polardns.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[main]
domain = 'yourdomain.com'
ns1 = '127.0.0.1'
ns2 = '127.0.0.1'

# server address
listen_addr = '0.0.0.0:53'

# debug (0 or 1)
debug = 0

# default TTL
ttl = 60

# default latency (in ms)
sleep = 0

# a 3rdparty domain which we don't own
a3rdparty_domain = 'whatever.com'

known_servers = """
127.0.0.1 localhost
1.2.3.4 powerdns1
1.2.3.5 powerdns2
2.3.4.5 bind-test1
4.5.6.7 msdns-test1
"""
34 changes: 0 additions & 34 deletions polardns.yml

This file was deleted.

0 comments on commit 49893ec

Please sign in to comment.