Skip to content
Draft

WIP #175

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
2 changes: 1 addition & 1 deletion .github/workflows/delete-pr-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- id: details
uses: kpfleming/composite-actions/image-details@v3
with:
base_image: python:trixie-main
base_image: python:v4-trixie-main
- uses: kpfleming/composite-actions/delete-pr-image@v3
with:
image_registry: ${{ steps.details.outputs.image_registry }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- id: details
uses: kpfleming/composite-actions/image-details@v3
with:
base_image: python:trixie-main
base_image: python:v4-trixie-main
- id: preflight
uses: kpfleming/composite-actions/lint-preflight@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- id: details
uses: kpfleming/composite-actions/image-details@v3
with:
base_image: python:trixie-main
base_image: python:v4-trixie-main
publish_galaxy:
runs-on: ubuntu-24.04-arm
outputs:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ requirements file will need to be installed there:
ansible.builtin.pip:
name:
- bravado
- dnspython
- jsonschema<4
- swagger-spec-validator==2.6.0
```
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bravado
dnspython
jsonschema<4
swagger-spec-validator==2.6.0
20 changes: 20 additions & 0 deletions src/plugins/module_utils/dns_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SPDX-FileCopyrightText: 2025 Kevin P. Fleming <[email protected]>
# SPDX-License-Identifier: Apache-2.0
# -*- coding: utf-8 -*-

import dns.exception
import dns.name


class DNSNameError(Exception):
"""The supplied DNS name was not valid."""

def __init__(self, name, location, e):
super().__init__(f"Invalid DNS name in '{location}': {name} - {e}")


def validate_dns_name(name, location):
try:
return dns.name.from_text(name).to_text()
except dns.exception.DNSException as e:
raise DNSNameError(name, location, e) from None
6 changes: 5 additions & 1 deletion src/plugins/modules/cryptokey.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from ..module_utils.api_module_args import API_MODULE_ARGS
from ..module_utils.api_wrapper import APICryptokeyWrapper, APIZoneWrapper
from ..module_utils.dns_helpers import validate_dns_name

assert sys.version_info >= (3, 10), "This module requires Python 3.9 or newer."

Expand All @@ -25,6 +26,7 @@

requirements:
- bravado
- dnspython

extends_documentation_fragment:
- kpfleming.powerdns_auth.api_details
Expand Down Expand Up @@ -248,8 +250,10 @@ def main():
result = {"changed": False, "cryptokeys": []}

params = module.params

state = params["state"]
zone_name = params["zone_name"]

zone_name = validate_dns_name(params["zone_name"], "zone_name")

api_zone_client = APIZoneWrapper(
module=module, result=result, object_type="zones", zone_id=None
Expand Down
1 change: 1 addition & 0 deletions src/plugins/modules/rrset.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

requirements:
- bravado
- dnspython

extends_documentation_fragment:
- kpfleming.powerdns_auth.api_details
Expand Down
25 changes: 13 additions & 12 deletions src/plugins/modules/tsigkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,15 @@ def main():

module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)

state = module.params["state"]
key = module.params["name"]

result = {
"changed": False,
}

params = module.params

state = params["state"]
name = params["name"]

if module.check_mode:
module.exit_json(**result)

Expand All @@ -176,13 +178,12 @@ def main():
# predictable exceptions
api_client = APITSIGKeyWrapper(module=module, result=result, object_type="tsigkey")

result["key"] = {"name": key, "exists": False}
result["key"] = {"name": name, "exists": False}

# first step is to get information about the key, if it exists
# this is required to translate the user-friendly key name into
# the key_id required for subsequent API calls

partial_key_info = [k for k in api_client.listTSIGKeys() if k["name"] == key]
partial_key_info = [k for k in api_client.listTSIGKeys() if k["name"] == name]

if len(partial_key_info) == 0:
if state in ("exists", "absent"):
Expand Down Expand Up @@ -214,12 +215,12 @@ def main():
if not key_id:
# create the requested key
key_struct = {
"name": key,
"algorithm": module.params["algorithm"],
"name": name,
"algorithm": params["algorithm"],
}

if module.params["key"]:
key_struct["key"] = module.params["key"]
if params["key"]:
key_struct["key"] = params["key"]

key_info = api_client.createTSIGKey(tsigkey=key_struct)
result["changed"] = True
Expand All @@ -231,10 +232,10 @@ def main():
# options and update it if necessary
key_struct = {}

if (mod_alg := module.params["algorithm"]) and mod_alg != key_info["algorithm"]:
if (mod_alg := params["algorithm"]) and mod_alg != key_info["algorithm"]:
key_struct["algorithm"] = mod_alg

if (mod_key := module.params["key"]) and mod_key != key_info["key"]:
if (mod_key := params["key"]) and mod_key != key_info["key"]:
key_struct["key"] = mod_key

if key_struct:
Expand Down
Loading
Loading