introduced config file
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
.venv
|
.venv
|
||||||
|
config.yml
|
||||||
|
|||||||
2
config.yml.example
Normal file
2
config.yml.example
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
configfile: "/etc/powerdns/pdns.d/mysql.conf" # Path to pdns configuration file with mysql login
|
||||||
@@ -2,6 +2,7 @@ import argparse
|
|||||||
import configparser
|
import configparser
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
import os
|
import os
|
||||||
|
import yaml
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog='pdns-tsig-from-catalog for PowerDNS',
|
prog='pdns-tsig-from-catalog for PowerDNS',
|
||||||
@@ -10,21 +11,24 @@ parser = argparse.ArgumentParser(
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--config',
|
'--config',
|
||||||
dest='config',
|
dest='config',
|
||||||
required=True,
|
default="config.yml",
|
||||||
help='powerdns config file, that inlcudes mysql login')
|
help='config file for this tool')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
with open(args.config, "r") as yamlfile:
|
||||||
|
config = yaml.safe_load(yamlfile)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
with open(args.config, 'r') as f:
|
pdnsconfig = configparser.ConfigParser()
|
||||||
|
with open(config["configfile"], 'r') as f:
|
||||||
config_string = '[default]\n' + f.read()
|
config_string = '[default]\n' + f.read()
|
||||||
config.read_string(config_string)
|
pdnsconfig.read_string(config_string)
|
||||||
|
|
||||||
mydb = mysql.connector.connect(
|
mydb = mysql.connector.connect(
|
||||||
host=config["default"]["gmysql-host"],
|
host=pdnsconfig["default"]["gmysql-host"],
|
||||||
user=config["default"]["gmysql-user"],
|
user=pdnsconfig["default"]["gmysql-user"],
|
||||||
password=config["default"]["gmysql-password"],
|
password=pdnsconfig["default"]["gmysql-password"],
|
||||||
database=config["default"]["gmysql-dbname"]
|
database=pdnsconfig["default"]["gmysql-dbname"]
|
||||||
)
|
)
|
||||||
|
|
||||||
mycursor = mydb.cursor(dictionary=True)
|
mycursor = mydb.cursor(dictionary=True)
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
configparser
|
configparser
|
||||||
mysql-connector-python
|
mysql-connector-python
|
||||||
|
PyYAML
|
||||||
|
|||||||
Reference in New Issue
Block a user