Skip to content
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
71 changes: 32 additions & 39 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: PR Jobs

on:
pull_request:

jobs:
pytest:
name: Python Tests
Expand All @@ -23,49 +21,45 @@ jobs:
- name: Test with pytest
run: |
pytest

black:
name: Python Style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- name: Run black
uses: psf/black@af0ba72a73598c76189d6dd1b21d8532255d5942 # v25
with:
options: ". --check --verbose"

- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- name: Run black
uses: psf/black@af0ba72a73598c76189d6dd1b21d8532255d5942 # v25
with:
options: ". --check --verbose"
pylint:
name: Python Lint
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.13"]
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/ci.txt
- name: Run pylint
run: |
pylint $(git ls-files '*.py' | grep -v dnspython)

- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/ci.txt
- name: Run pylint
run: |
pylint $(git ls-files '*.py' | grep -v dnspython)
eslint:
name: JS Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 # v2
- name: Setup Bun and Run ESLint
run: |
bun init -y
bun add eslint @eslint/js
bunx eslint

- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 # v2
- name: Setup Bun and Run ESLint
run: |
bun init -y
bun add eslint @eslint/js globals
bunx eslint
stylelint:
name: CSS Lint
runs-on: ubuntu-latest
Expand All @@ -77,16 +71,15 @@ jobs:
bun init -y
bun install stylelint stylelint-config-standard
bunx stylelint static/css/*.css

actionlint:
name: 'Github Actions YAML Lint'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- name: Download actionlint
run: |
VERSION="1.7.7"
ARCH=$(dpkg --print-architecture)
wget -c "https://github.com/rhysd/actionlint/releases/download/v${VERSION}/actionlint_${VERSION}_linux_${ARCH}.tar.gz" -O - | tar -xz
- name: Check workflow files
run: ./actionlint -shellcheck= -pyflakes= -color
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- name: Download actionlint
run: |
VERSION="1.7.7"
ARCH=$(dpkg --print-architecture)
wget -c "https://github.com/rhysd/actionlint/releases/download/v${VERSION}/actionlint_${VERSION}_linux_${ARCH}.tar.gz" -O - | tar -xz
- name: Check workflow files
run: ./actionlint -shellcheck= -pyflakes= -color
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ module.exports = defineConfig([
}]
},
},
]);
]);
2 changes: 1 addition & 1 deletion static/js/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function setButtonsDisplay(row, isEditing) {
function getRecordDataFromCell(dataCellList) {
let returnDict = {};
dataCellList.forEach(dataCell => {
let data = '';
let data;
const input = dataCell.querySelector('input');
if (input) {
data = input.value.trim();
Expand Down
4 changes: 3 additions & 1 deletion zoneforge/api/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ def post(self, zone_name: str):
Creates a new DNS record in the specified zone.
"""
args = record_post_parser.parse_args()
ttl = args.get("ttl", None)

new_record = create_record(
zone_name=zone_name,
zonefile_folder=current_app.config["ZONE_FILE_FOLDER"],
record_name=args["name"],
record_type=args["type"],
record_ttl=args["ttl"],
record_ttl=ttl,
record_data=args["data"],
record_comment=args["comment"],
)
Expand Down
27 changes: 19 additions & 8 deletions zoneforge/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import glob
import re
import importlib
import logging
import re
from datetime import datetime
from os import remove
from os.path import join, exists, basename
from os.path import basename, exists, join
from typing import Type

import dns.immutable
import dns.node
import dns.name
import dns.rdatatype
import dns.rdtypes.txtbase
import dns.zone
import dns.node
import dns.rdata
import dns.rdataset
import dns.rdatatype
import dns.rdtypes.txtbase
import dns.rrset
import dns.versioned
import dns.transaction
import dns.versioned
import dns.zone
from werkzeug.exceptions import * # pylint: disable=wildcard-import,unused-wildcard-import,redefined-builtin

RECORD_FIELDS_TO_RELATIVIZE = [
Expand Down Expand Up @@ -91,6 +92,10 @@ def get_all_records(self, record_type: str = None, include_soa: bool = False):
]
return list(all_records)

def get_default_ttl(self):
# zone.get_soa() SOA class doesnt expose TTL
return super().get_rrset(name="@", rdtype="SOA").ttl


def get_zones(zonefile_folder: str, zone_name: dns.name.Name = None) -> list[ZFZone]:
zonefile_map = {}
Expand Down Expand Up @@ -211,8 +216,8 @@ def create_record(
record_name: str,
record_type: str,
record_data: dict,
record_ttl: int,
zonefile_folder: str,
record_ttl: int = None,
zone_name: dns.name.Name = None,
record_class: dns.rdataclass.RdataClass = "IN",
record_comment: str = None,
Expand All @@ -221,6 +226,7 @@ def create_record(

# perform validation only when we're writing to disk. creating a new zone requires we have the record objects first.
matching_rrset = None
zone = None
if write:
if not zone_name:
raise ValueError("A zone_name must be provided to write to a zone file.")
Expand All @@ -230,6 +236,11 @@ def create_record(
zone = zone[0]
matching_rrset = zone.get_rrset(name=record_name, rdtype=record_type)

if record_ttl is None:
if zone is None:
raise ValueError("A zone_name must be provided to inherit TTL")
record_ttl = zone.get_default_ttl()

new_rdata = request_to_rdata(
zone_name=zone_name,
record_type=record_type,
Expand Down