Add a flag to modify config.json location
On Kubernetes, it's really awkward to write a Secret into the root directory: https://www.jeffgeerling.com/blog/2019/mounting-kubernetes-secret-single-file-inside-pod Therefore this adds support for reading the config from an arbitrary path. The behaviour is unchanged if you don't set this new flag.
This commit is contained in:
parent
8c55892f32
commit
0f3708a482
@ -21,9 +21,6 @@ class GracefulExit:
|
||||
print("🛑 Stopping main thread...")
|
||||
self.kill_now = True
|
||||
|
||||
with open(PATH + "config.json") as config_file:
|
||||
config = json.loads(config_file.read())
|
||||
|
||||
def deleteEntries(type):
|
||||
# Helper function for deleting A or AAAA records
|
||||
# in the case of no IPv4 or IPv6 connection, yet
|
||||
@ -70,7 +67,7 @@ def getIPs():
|
||||
})
|
||||
return ips
|
||||
|
||||
def commitRecord(ip):
|
||||
def commitRecord(ip, config):
|
||||
for c in config["cloudflare"]:
|
||||
subdomains = c["subdomains"]
|
||||
response = cf_api("zones/" + c['zone_id'], "GET", c)
|
||||
@ -143,13 +140,14 @@ def cf_api(endpoint, method, config, headers={}, data=False):
|
||||
|
||||
return response.json()
|
||||
|
||||
def updateIPs():
|
||||
def updateIPs(config):
|
||||
for ip in getIPs():
|
||||
commitRecord(ip)
|
||||
commitRecord(ip, config)
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--repeat", type=bool)
|
||||
parser.add_argument("--config-path", dest="config", type=open, default=os.path.join(PATH, "config.json"))
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.repeat:
|
||||
@ -159,8 +157,8 @@ if __name__ == '__main__':
|
||||
killer = GracefulExit()
|
||||
while not killer.kill_now:
|
||||
time.sleep(max(0, next_time - time.time()))
|
||||
updateIPs()
|
||||
updateIPs(json.load(args.config))
|
||||
next_time += (time.time() - next_time) // delay * delay + delay
|
||||
else:
|
||||
updateIPs()
|
||||
updateIPs(json.load(args.config))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user