Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace yaml to toml #3

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.