Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict the length of JSON output indent to 32 #288

Merged
merged 1 commit into from
May 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/ipahealthcheck/core/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (C) 2019 FreeIPA Contributors see COPYING for license
#

from argparse import ArgumentTypeError
from datetime import datetime
import json
import sys
Expand All @@ -16,6 +17,26 @@ class OutputRegistry(Registry):
output_registry = OutputRegistry()


class Int:
def __init__(self, minimum=0, maximum=100):
self.minimum = minimum
self.maximum = maximum

def __call__(self, arg):
try:
value = int(arg)
except ValueError:
raise ArgumentTypeError("'%s' is not an integer" % arg)

if (value < self.minimum) or (value > self.maximum):
raise ArgumentTypeError(
"'%s' is not in the range %s-%s"
% (value, self.minimum, self.maximum)
)

return value


class Output:
"""Base class for writing/displaying the output of results

Expand Down Expand Up @@ -105,7 +126,7 @@ class JSON(Output):
"""Output information in JSON format"""

options = (
('--indent', dict(dest='indent', type=int, default=2,
('--indent', dict(dest='indent', type=Int(0, 32), default=2,
help='Indention level of JSON output')),
)

Expand Down