Skip to content

Commit

Permalink
add dry-run into the config
Browse files Browse the repository at this point in the history
  • Loading branch information
azlux committed Aug 30, 2023
1 parent e3f6a52 commit a311059
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions nft-dns.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[GLOBAL]
#max_ttl = 86400
#min_ttl = 10
#min_ttl = 300
#mode = capture
#custom_resolver = "1.1.1.1"
#verbose = True
#dry_run = False
#verbose = False
include_config_dir = /etc/nft-dns.d/

#[debian]
Expand Down
4 changes: 2 additions & 2 deletions nft-dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def read_config():
list_set = list(set([i.set_name for i in values])) # get all nft named set once
for set_name in list_set:
res = run_command(f"nft list set filter {set_name}")
if not args.dry_run:
if not (args.dry_run or (config.has_option('GLOBAL', 'verbose') and config['GLOBAL'].getboolean('dry_run', fallback=False))):
if "ipv4_addr" in res or "ipv6_addr" in res:
logging.debug(f"set {set_name} well defined")
else:
Expand Down Expand Up @@ -132,7 +132,7 @@ def apply_config_entry(one_entry: entry.ModelEntry, old_ip_list: List[IPvAnyAddr

def run_command(cmd: str) -> str:
logging.debug(f"Command to run : {cmd}")
if not args.dry_run:
if not (args.dry_run or (config.has_option('GLOBAL', 'verbose') and config['GLOBAL'].getboolean('dry_run', fallback=False))):
try:
res = subprocess.run(cmd, capture_output=True, text=True, check=True, shell=True)
return res.stdout
Expand Down

0 comments on commit a311059

Please sign in to comment.