Skip to content

Commit

Permalink
Make CLI related functions and classes private
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hamann committed Jun 29, 2024
1 parent 23ed5bb commit b34c762
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions desec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ def update_record(
return self.change_record(domain, rtype, subname, rrset)


def print_records(rrset: JsonRRsetType | JsonRRsetFromZonefileType, **kwargs: t.Any) -> None:
def _print_records(rrset: JsonRRsetType | JsonRRsetFromZonefileType, **kwargs: t.Any) -> None:
"""Print a RRset in zone file format.
Args:
Expand All @@ -1236,7 +1236,7 @@ def print_records(rrset: JsonRRsetType | JsonRRsetFromZonefileType, **kwargs: t.
print(line, **kwargs)


def print_rrsets(
def _print_rrsets(
rrsets: t.Sequence[JsonRRsetType | JsonRRsetFromZonefileType], **kwargs: t.Any
) -> None:
"""Print multiple RRsets in zone file format.
Expand All @@ -1247,7 +1247,7 @@ def print_rrsets(
"""
for rrset in rrsets:
print_records(rrset, **kwargs)
_print_records(rrset, **kwargs)

Check warning on line 1250 in desec.py

View check run for this annotation

Codecov / codecov/patch

desec.py#L1250

Added line #L1250 was not covered by tests


def sanitize_records(rtype: DnsRecordTypeType, subname: str, rrset: list[str]) -> list[str]:
Expand Down Expand Up @@ -1484,7 +1484,7 @@ def tlsa_record(
return f"{int(usage)} {int(selector)} {int(match_type)} {hex_data}"


class CliClientFormatter(logging.Formatter):
class _CliClientFormatter(logging.Formatter):
"""Pretty prints requests and response logs for CLI usage."""

def format(self, record: logging.LogRecord) -> str:
Expand All @@ -1511,21 +1511,21 @@ def format(self, record: logging.LogRecord) -> str:
return message


def configure_cli_logging(level: int) -> None:
def _configure_cli_logging(level: int) -> None:
"""Set up logging configuration when using the module as a command-line interface.
Args:
level: Logging level to set for desec.client logger.
"""
http_handler = logging.StreamHandler(stream=sys.stderr)
http_formatter = CliClientFormatter()
http_formatter = _CliClientFormatter()

Check warning on line 1521 in desec.py

View check run for this annotation

Codecov / codecov/patch

desec.py#L1521

Added line #L1521 was not covered by tests
http_handler.setFormatter(http_formatter)
http_logger = logging.getLogger("desec.client")
http_logger.addHandler(http_handler)
http_logger.setLevel(level)


def main() -> None:
def _main() -> None:
"""Main CLI entry point."""
parser = argparse.ArgumentParser(description="A simple deSEC.io API client")
p_action = parser.add_subparsers(dest="action", metavar="action")
Expand Down Expand Up @@ -1940,7 +1940,7 @@ def main() -> None:

arguments = parser.parse_args()
del p_action, g, p, parser
configure_cli_logging(level=logging.DEBUG if arguments.debug_http else logging.INFO)
_configure_cli_logging(level=logging.DEBUG if arguments.debug_http else logging.INFO)

Check warning on line 1943 in desec.py

View check run for this annotation

Codecov / codecov/patch

desec.py#L1943

Added line #L1943 was not covered by tests

if arguments.token:
token = arguments.token
Expand Down Expand Up @@ -2016,7 +2016,7 @@ def main() -> None:
arguments.domain, arguments.type, arguments.subname
)
for rrset in rrsets_result:
print_records(rrset)
_print_records(rrset)

Check warning on line 2019 in desec.py

View check run for this annotation

Codecov / codecov/patch

desec.py#L2019

Added line #L2019 was not covered by tests

elif arguments.action == "add-record":
arguments.records = sanitize_records(
Expand All @@ -2029,7 +2029,7 @@ def main() -> None:
arguments.records,
arguments.ttl,
)
print_records(rrset_result)
_print_records(rrset_result)

Check warning on line 2032 in desec.py

View check run for this annotation

Codecov / codecov/patch

desec.py#L2032

Added line #L2032 was not covered by tests

elif arguments.action == "change-record":
arguments.records = sanitize_records(
Expand All @@ -2042,7 +2042,7 @@ def main() -> None:
arguments.records,
arguments.ttl,
)
print_records(rrset_result)
_print_records(rrset_result)

Check warning on line 2045 in desec.py

View check run for this annotation

Codecov / codecov/patch

desec.py#L2045

Added line #L2045 was not covered by tests

elif arguments.action == "update-record":
arguments.records = sanitize_records(
Expand All @@ -2055,7 +2055,7 @@ def main() -> None:
arguments.records,
arguments.ttl,
)
print_records(rrset_result)
_print_records(rrset_result)

Check warning on line 2058 in desec.py

View check run for this annotation

Codecov / codecov/patch

desec.py#L2058

Added line #L2058 was not covered by tests

elif arguments.action == "delete-record":
if arguments.records:
Expand Down Expand Up @@ -2101,7 +2101,7 @@ def main() -> None:
)

rrsets_result = api_client.update_bulk_record(arguments.domain, records)
print_rrsets(rrsets_result)
_print_rrsets(rrsets_result)

Check warning on line 2104 in desec.py

View check run for this annotation

Codecov / codecov/patch

desec.py#L2104

Added line #L2104 was not covered by tests

elif arguments.action == "export":
rrsets_result = api_client.get_records(arguments.domain)
Expand All @@ -2127,7 +2127,7 @@ def main() -> None:
rrsets_result = api_client.update_bulk_record(
arguments.domain, records, arguments.clear
)
print_rrsets(rrsets_result)
_print_rrsets(rrsets_result)

Check warning on line 2130 in desec.py

View check run for this annotation

Codecov / codecov/patch

desec.py#L2130

Added line #L2130 was not covered by tests

elif arguments.action == "import-zone":
record_list = parse_zone_file(
Expand All @@ -2146,17 +2146,17 @@ def main() -> None:
"Dry run. Not writing changes to API. I would have written this:",
file=sys.stderr,
)
print_rrsets(record_list)
_print_rrsets(record_list)

Check warning on line 2149 in desec.py

View check run for this annotation

Codecov / codecov/patch

desec.py#L2149

Added line #L2149 was not covered by tests
else:
rrsets_result = api_client.update_bulk_record(
arguments.domain, record_list, arguments.clear
)
print_rrsets(rrsets_result)
_print_rrsets(rrsets_result)

Check warning on line 2154 in desec.py

View check run for this annotation

Codecov / codecov/patch

desec.py#L2154

Added line #L2154 was not covered by tests

except DesecClientError as e:
print(str(e))
sys.exit(e.error_code)


if __name__ == "__main__":
main()
_main()

0 comments on commit b34c762

Please sign in to comment.