Skip to content

Commit

Permalink
Dont allow duplicates for a record by wiping zone every run (#2)
Browse files Browse the repository at this point in the history
* some general fixes

* Dont allow duplicates for a record by wiping zone every run

* small fix
  • Loading branch information
aaronsteed authored Nov 13, 2023
1 parent f12c0bf commit ba21cf2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ ARG ZONE
ARG RECORD_NAME
ARG RECORD_VALUE

# Specification of OCI labels here: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#labelling-container-images
LABEL authors="aaronsteed"
LABEL org.opencontainers.image.source="https://github.com/aaronsteed/dns-kube-job/"
LABEL org.opencontainers.image.description="App to create a DNS record in Technitium DNS from environment variables"


RUN pip install poetry
COPY . /app
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ docker build -t ghcr.io/aaronsteed/dns-kube-job:latest .
Note: Consider using a secret in Kubernetes for `password`
## Running project locally
```shell
python -m dns-kube-
python -m dns-kube-job.main
```
12 changes: 12 additions & 0 deletions dns-kube-job/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ def endpoint_is_accessible(dns_endpoint) -> bool:
return False


def ensure_no_previous_record(zone_name, dns_endpoint, record_name, generated_token):
"""ensure that the record name does not currently exist in Technitium DNS server
will cause issues where multiple IPs will be returned if duplicate entries for a record name present
Only nice way to do this is deleting and recreating zone
"""
response = requests.get(f"{dns_endpoint}/api/zones/delete?token={generated_token}&zone={zone_name}")
print("evaluated : " + f"{dns_endpoint}/api/zones/delete?token={generated_token}&zone={zone_name}")
print(response.content)


def main():
dns_endpoint = os.getenv("DNS_ENDPOINT") # e.g. http://localhost:56196

Expand All @@ -42,6 +52,8 @@ def main():

generated_token = generate_token(dns_endpoint, username, password, token_name)

ensure_no_previous_record(zone_name, dns_endpoint, record_name, generated_token)

if not zone_already_exists(dns_endpoint, generated_token, zone_name):
requests.get(f"{dns_endpoint}/api/zones/create?token={generated_token}&zone={zone_name}")

Expand Down

0 comments on commit ba21cf2

Please sign in to comment.