Skip to content

Commit b336b06

Browse files
author
IamLunchbox
committed
Feature: Add a launcher to view the corresponding api spec of the action
1 parent 1137096 commit b336b06

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

powerdns_cli/powerdns_cli.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ def autoprimary_list(ctx):
251251
raise SystemExit(1)
252252

253253

254+
@autoprimary.command("spec")
255+
def autoprimary_spec():
256+
"""Open the autoprimary specification on https://redocly.github.io"""
257+
258+
utils.open_spec("autoprimary")
259+
260+
254261
@cli.group()
255262
def config():
256263
"""Overall server configuration"""
@@ -295,6 +302,13 @@ def config_stats(ctx):
295302
raise SystemExit(1)
296303

297304

305+
@config.command("spec")
306+
def config_spec():
307+
"""Open the config specification on https://redocly.github.io"""
308+
309+
utils.open_spec("config")
310+
311+
298312
@cli.group()
299313
def cryptokey():
300314
"""Configure cryptokeys"""
@@ -541,6 +555,13 @@ def cryptokey_publish(ctx, dns_zone, cryptokey_id):
541555
raise SystemExit(1)
542556

543557

558+
@cryptokey.command("spec")
559+
def cryptokey_spec():
560+
"""Open the cryptokey specification on https://redocly.github.io"""
561+
562+
utils.open_spec("cryptokey")
563+
564+
544565
@cryptokey.command("unpublish")
545566
@click.pass_context
546567
@click.argument("dns_zone", type=PowerDNSZone, metavar="zone")
@@ -663,6 +684,13 @@ def network_delete(ctx, cidr):
663684
raise SystemExit(1)
664685

665686

687+
@network.command("spec")
688+
def network_spec():
689+
"""Open the network specification on https://redocly.github.io"""
690+
691+
utils.open_spec("network")
692+
693+
666694
@cli.group()
667695
def record():
668696
"""Resource records of a zone"""
@@ -1020,6 +1048,12 @@ def record_export(
10201048
raise SystemExit(1)
10211049

10221050

1051+
@record.command("spec")
1052+
def record_spec():
1053+
"""Open the record specification on https://redocly.github.io"""
1054+
utils.open_spec("record")
1055+
1056+
10231057
@cli.group()
10241058
def tsigkey():
10251059
"""Set up tsigkeys"""
@@ -1118,6 +1152,13 @@ def tsigkey_list(ctx):
11181152
raise SystemExit(1)
11191153

11201154

1155+
@tsigkey.command("spec")
1156+
def tsigkey_spec():
1157+
"""Open the tsigkey specification on https://redocly.github.io"""
1158+
1159+
utils.open_spec("tsigkey")
1160+
1161+
11211162
@tsigkey.command("update")
11221163
@click.argument("name", type=click.STRING)
11231164
@click.option(
@@ -1306,6 +1347,13 @@ def zone_rectify(ctx, dns_zone):
13061347
raise SystemExit(1)
13071348

13081349

1350+
@zone.command("spec")
1351+
def zone_spec():
1352+
"""Open the zone specification on https://redocly.github.io"""
1353+
1354+
utils.open_spec("zone")
1355+
1356+
13091357
@zone.command("search")
13101358
@click.argument("search-string", metavar="STRING")
13111359
@click.option("--max", "max_output", help="Number of items to output", default=5, type=click.INT)
@@ -1430,6 +1478,12 @@ def metadata_list(ctx, dns_zone, limit):
14301478
raise SystemExit(1)
14311479

14321480

1481+
@metadata.command("spec")
1482+
def metadata_spec():
1483+
"""Open the metadata specification on https://redocly.github.io"""
1484+
utils.open_spec("metadata")
1485+
1486+
14331487
@metadata.command("update")
14341488
@click.argument("dns_zone", type=PowerDNSZone, metavar="zone")
14351489
@click.argument("metadata-key", type=click.STRING)
@@ -1542,6 +1596,13 @@ def view_list(ctx):
15421596
raise SystemExit(1)
15431597

15441598

1599+
@view.command("spec")
1600+
def view_spec():
1601+
"""Open the view specification on https://redocly.github.io"""
1602+
1603+
utils.open_spec("view")
1604+
1605+
15451606
# pylint: disable=unused-argument
15461607
@view.command("update")
15471608
@click.argument("view_id", type=click.STRING, metavar="view")

powerdns_cli/utils.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,38 @@ def merge_rrsets(uri: str, ctx: click.Context, new_rrset: dict) -> list:
240240
]
241241
)
242242
return merged_rrsets
243+
244+
245+
def open_spec(action: str) -> SystemExit:
246+
"""Opens the api spec on https://redocly.github.io with your default browser"""
247+
action = action.lower()
248+
match action:
249+
case "autoprimary":
250+
tag = "/autoprimary"
251+
case "cryptokey":
252+
tag = "/zonecryptokey"
253+
case "config":
254+
tag = "/config"
255+
case "metadata":
256+
tag = "/zonemetadata"
257+
case "network":
258+
tag = "/networks"
259+
case "record":
260+
tag = "/zones/operation/patchZone"
261+
case "search":
262+
tag = "/search"
263+
case "tsigkey":
264+
tag = "/tsigkey"
265+
case "view":
266+
tag = "/views"
267+
case "zone":
268+
tag = "/zones"
269+
case _:
270+
tag = ""
271+
url = (
272+
f"https://redocly.github.io/redoc/?url="
273+
f"https://raw.githubusercontent.com/PowerDNS/pdns/"
274+
f"refs/heads/master/docs/http-api/swagger/authoritative-api-swagger.yaml"
275+
f"#tag{tag}"
276+
)
277+
raise SystemExit(click.launch(url))

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ license = "GPL-3.0-or-later"
1313
classifiers = [
1414
"Programming Language :: Python :: 3",
1515
]
16-
version = "0.0.18"
16+
version = "0.0.19"
1717
dependencies = [
1818
"requests==2.32.5",
1919
"click==8.2.1"

0 commit comments

Comments
 (0)