@@ -230,7 +230,10 @@ def autoprimary_delete(ctx, ip, nameserver):
230230 raise SystemExit (0 )
231231 else :
232232 click .echo (
233- json .dumps ({"message" : f"Autoprimary { ip } with nameserver { nameserver } already absent" })
233+ json .dumps (
234+ {"message" : f"Autoprimary { ip } with nameserver { nameserver } already absent" },
235+ indent = 4 ,
236+ )
234237 )
235238 raise SystemExit (0 )
236239
@@ -375,7 +378,11 @@ def cryptokey_disable(ctx, dns_zone, cryptokey_id):
375378 }
376379 r = utils .does_cryptokey_exist (uri , f"Cryptokey with id { cryptokey_id } does not exist" , 1 , ctx )
377380 if not r .json ()["active" ]:
378- click .echo (json .dumps ({"message" : f"Cryptokey with id { cryptokey_id } is already inactive" }))
381+ click .echo (
382+ json .dumps (
383+ {"message" : f"Cryptokey with id { cryptokey_id } is already inactive" }, indent = 4
384+ )
385+ )
379386 raise SystemExit (0 )
380387 r = utils .http_put (uri , ctx , payload )
381388 if utils .create_output (
@@ -405,7 +412,9 @@ def cryptokey_enable(ctx, dns_zone, cryptokey_id):
405412 }
406413 r = utils .does_cryptokey_exist (uri , f"Cryptokey with id { cryptokey_id } does not exist" , 1 , ctx )
407414 if r .json ()["active" ]:
408- click .echo (json .dumps ({"message" : f"Cryptokey with id { cryptokey_id } is already active" }))
415+ click .echo (
416+ json .dumps ({"message" : f"Cryptokey with id { cryptokey_id } is already active" }, indent = 4 )
417+ )
409418 raise SystemExit (0 )
410419 r = utils .http_put (uri , ctx , payload )
411420 if utils .create_output (
@@ -471,7 +480,9 @@ def cryptokey_import(
471480 }
472481 if utils .is_dnssec_key_present (uri , secret , ctx ):
473482 click .echo (
474- json .dumps ({"message" : "The provided dnssec-key is already present at the backend" })
483+ json .dumps (
484+ {"message" : "The provided dnssec-key is already present at the backend" }, indent = 4
485+ )
475486 )
476487 raise SystemExit (0 )
477488 r = utils .http_post (uri , ctx , payload )
@@ -515,7 +526,9 @@ def cryptokey_publish(ctx, dns_zone, cryptokey_id):
515526 }
516527 r = utils .does_cryptokey_exist (uri , f"Cryptokey with id { cryptokey_id } does not exist" , 1 , ctx )
517528 if r .json ()["published" ]:
518- click .echo (json .dumps ({"message" : f"Cryptokey with id { cryptokey_id } already published" }))
529+ click .echo (
530+ json .dumps ({"message" : f"Cryptokey with id { cryptokey_id } already published" }, indent = 4 )
531+ )
519532 raise SystemExit (0 )
520533 payload ["active" ] = r .json ()["active" ]
521534 r = utils .http_put (uri , ctx , payload )
@@ -547,7 +560,9 @@ def cryptokey_unpublish(ctx, dns_zone, cryptokey_id):
547560 r = utils .does_cryptokey_exist (uri , f"Cryptokey with id { cryptokey_id } does not exist" , 1 , ctx )
548561 if not r .json ()["published" ]:
549562 click .echo (
550- json .dumps ({"message" : f"Cryptokey with id { cryptokey_id } is already unpublished" })
563+ json .dumps (
564+ {"message" : f"Cryptokey with id { cryptokey_id } is already unpublished" }, indent = 4
565+ )
551566 )
552567 raise SystemExit (0 )
553568 payload ["active" ] = r .json ()["active" ]
@@ -566,7 +581,11 @@ def cryptokey_unpublish(ctx, dns_zone, cryptokey_id):
566581def network (ctx ):
567582 """Shows and sets up network views to limit access to dns entries"""
568583 if ctx .obj ["major_version" ] < 5 :
569- click .echo (json .dumps ({"error" : "Your authoritative dns-server does not support networks" }))
584+ click .echo (
585+ json .dumps (
586+ {"error" : "Your authoritative dns-server does not support networks" }, indent = 4
587+ )
588+ )
570589 raise SystemExit (1 )
571590
572591
@@ -582,7 +601,11 @@ def network_add(ctx, cidr, view_id):
582601 uri = f"{ ctx .obj ['apihost' ]} /api/v1/servers/localhost/networks/{ cidr } "
583602 current_network = utils .http_get (uri , ctx )
584603 if current_network .status_code == 200 and current_network .json ()["view" ] == view_id :
585- click .echo (json .dumps ({"message" : f"Network { cidr } is already assigned to view { view_id } " }))
604+ click .echo (
605+ json .dumps (
606+ {"message" : f"Network { cidr } is already assigned to view { view_id } " }, indent = 4
607+ )
608+ )
586609 raise SystemExit (0 )
587610 payload = {"view" : view_id }
588611 r = utils .http_put (uri , ctx , payload = payload )
@@ -629,7 +652,7 @@ def network_delete(ctx, cidr):
629652 uri = f"{ ctx .obj ['apihost' ]} /api/v1/servers/localhost/networks/{ cidr } "
630653 current_network = utils .http_get (uri , ctx )
631654 if current_network .status_code == 404 :
632- click .echo (json .dumps ({"message" : f"Network { cidr } absent" }))
655+ click .echo (json .dumps ({"message" : f"Network { cidr } absent" }, indent = 4 ))
633656 raise SystemExit (0 )
634657 payload = {"view" : "" }
635658 r = utils .http_put (uri , ctx , payload = payload )
@@ -690,7 +713,9 @@ def record_add(
690713 "records" : [{"content" : content , "disabled" : False }],
691714 }
692715 if utils .is_content_present (uri , ctx , rrset ):
693- click .echo (json .dumps ({"message" : f"{ name } { record_type } { content } already present" }))
716+ click .echo (
717+ json .dumps ({"message" : f"{ name } { record_type } { content } already present" }, indent = 4 )
718+ )
694719 raise SystemExit (0 )
695720
696721 r = utils .http_patch (uri , ctx , {"rrsets" : [rrset ]})
@@ -749,7 +774,9 @@ def record_delete(ctx, name, dns_zone, record_type, content, ttl, delete_all):
749774 "records" : [],
750775 }
751776 if not utils .is_matching_rrset_present (uri , ctx , rrset ):
752- click .echo (json .dumps ({"message" : f"{ record_type } records in { name } already absent" }))
777+ click .echo (
778+ json .dumps ({"message" : f"{ record_type } records in { name } already absent" }, indent = 4 )
779+ )
753780 raise SystemExit (0 )
754781 r = utils .http_patch (uri , ctx , {"rrsets" : [rrset ]})
755782 msg = {"message" : f"All { record_type } records for { name } removed" }
@@ -932,7 +959,9 @@ def record_extend(
932959 "records" : [{"content" : content , "disabled" : False }],
933960 }
934961 if utils .is_content_present (uri , ctx , rrset ):
935- click .echo (json .dumps ({"message" : f"{ name } IN { record_type } { content } already present" }))
962+ click .echo (
963+ json .dumps ({"message" : f"{ name } IN { record_type } { content } already present" }, indent = 4 )
964+ )
936965 raise SystemExit (0 )
937966 upstream_rrset = utils .is_matching_rrset_present (uri , ctx , rrset )
938967 if upstream_rrset :
@@ -1167,7 +1196,7 @@ def zone_add(ctx, dns_zone, zonetype, master):
11671196 }
11681197 current_zones = utils .query_zones (ctx )
11691198 if [z for z in current_zones if z ["name" ] == dns_zone ]:
1170- click .echo (json .dumps ({"message" : f"Zone { dns_zone } already present" }))
1199+ click .echo (json .dumps ({"message" : f"Zone { dns_zone } already present" }, indent = 4 ))
11711200 raise SystemExit (0 )
11721201 r = utils .http_post (uri , ctx , payload )
11731202 if utils .create_output (r , (201 ,), optional_json = {"message" : f"Zone { dns_zone } created" }):
@@ -1192,16 +1221,14 @@ def zone_delete(ctx, dns_zone, force):
11921221 """
11931222 upstream_zones = utils .query_zones (ctx )
11941223 if dns_zone not in [single_zone ["name" ] for single_zone in upstream_zones ]:
1195- click .echo (json .dumps ({"message" : f"{ dns_zone } already absent" }))
1224+ click .echo (json .dumps ({"message" : f"{ dns_zone } already absent" }, indent = 4 ))
11961225 raise SystemExit (0 )
11971226
11981227 uri = f"{ ctx .obj ['apihost' ]} /api/v1/servers/localhost/zones/{ dns_zone } "
1199- utils .confirm (
1200- f"!!!! WARNING !!!!!\n "
1201- f"You are attempting to delete { dns_zone } \n "
1202- f"Are you sure? [y/N] " ,
1203- force ,
1204- )
1228+ warning = f"!!!! WARNING !!!!!\n You are attempting to delete { dns_zone } \n Are you sure?"
1229+ if not force and not click .confirm (warning ):
1230+ click .echo (json .dumps ({"message" : f"Aborted deleting { dns_zone } " }, indent = 4 ))
1231+ raise SystemExit (1 )
12051232 r = utils .http_delete (uri , ctx )
12061233 msg = {"message" : f"{ dns_zone } deleted" }
12071234 if utils .create_output (r , (204 ,), optional_json = msg ):
@@ -1359,7 +1386,7 @@ def metadata_delete(ctx, dns_zone, metadata_key):
13591386 ):
13601387 raise SystemExit (0 )
13611388 raise SystemExit (1 )
1362- click .echo (json .dumps ({"message" : f"{ metadata_key } for { dns_zone } already absent" }))
1389+ click .echo (json .dumps ({"message" : f"{ metadata_key } for { dns_zone } already absent" }, indent = 4 ))
13631390 raise SystemExit (0 )
13641391
13651392
@@ -1420,7 +1447,9 @@ def metadata_update(ctx, dns_zone, metadata_key, metadata_value):
14201447 raise SystemExit (0 )
14211448 raise SystemExit (1 )
14221449 click .echo (
1423- json .dumps ({"message" : f"{ metadata_key } :{ metadata_value } for { dns_zone } already present" })
1450+ json .dumps (
1451+ {"message" : f"{ metadata_key } :{ metadata_value } for { dns_zone } already present" }, indent = 4
1452+ )
14241453 )
14251454 raise SystemExit (0 )
14261455
@@ -1439,7 +1468,9 @@ def print_version():
14391468def view (ctx ):
14401469 """Set view to limit zone access"""
14411470 if ctx .obj ["major_version" ] < 5 :
1442- click .echo (json .dumps ({"error" : "Your authoritative dns-server does not support views" }))
1471+ click .echo (
1472+ json .dumps ({"error" : "Your authoritative dns-server does not support views" }, indent = 4 )
1473+ )
14431474 raise SystemExit (1 )
14441475
14451476
@@ -1452,7 +1483,7 @@ def view_add(ctx, view_id, dns_zone):
14521483 uri = f"{ ctx .obj ['apihost' ]} /api/v1/servers/localhost/views/{ view_id } "
14531484 view_content = utils .http_get (uri , ctx )
14541485 if view_content .status_code == 200 and dns_zone in view_content .json ()["zones" ]:
1455- click .echo (json .dumps ({"message" : f"{ dns_zone } already in { view_id } " }))
1486+ click .echo (json .dumps ({"message" : f"{ dns_zone } already in { view_id } " }, indent = 4 ))
14561487 raise SystemExit (0 )
14571488 payload = {"name" : f"{ dns_zone } " }
14581489 r = utils .http_post (uri , ctx , payload = payload )
@@ -1470,10 +1501,10 @@ def view_delete(ctx, view_id, dns_zone):
14701501 uri = f"{ ctx .obj ['apihost' ]} /api/v1/servers/localhost/views/{ view_id } "
14711502 view_content = utils .http_get (uri , ctx )
14721503 if view_content .status_code == 200 and dns_zone not in view_content .json ()["zones" ]:
1473- click .echo (json .dumps ({"message" : f"Zone { dns_zone } is not in { view_id } " }))
1504+ click .echo (json .dumps ({"message" : f"Zone { dns_zone } is not in { view_id } " }, indent = 4 ))
14741505 raise SystemExit (0 )
14751506 if view_content .status_code == 404 :
1476- click .echo (json .dumps ({"message" : f"View { view_id } is absent" }))
1507+ click .echo (json .dumps ({"message" : f"View { view_id } is absent" }, indent = 4 ))
14771508 raise SystemExit (0 )
14781509 uri = f"{ ctx .obj ['apihost' ]} /api/v1/servers/localhost/views/{ view_id } /{ dns_zone } "
14791510 r = utils .http_delete (uri , ctx )
0 commit comments