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

add report to file #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
27 changes: 25 additions & 2 deletions scripts/plugin_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ def parse_args(
help="print results for all resources (ignored for tap and junit output)",
action="store_true",
)
group_kubeconform.add_argument(
"--report",
metavar="FILE",
help="config file name (default: .kubeconform)",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my mistake

default="report.txt",
)

if add_files:
parser.add_argument(
Expand Down Expand Up @@ -301,6 +307,9 @@ def parse_args(
if a.verbose is True:
args["kubeconform"] += ["-verbose"]

if a.report:
args["kubeconform"] += ["-report", os.path.expanduser(a.report)]

# ### All args are wrapper options
args["wrapper"] = a

Expand Down Expand Up @@ -496,6 +505,13 @@ def run_kubeconform(args, input):
bin_file = helm_plugin_bin

# Create the cache dir
if "-report" in args:
r_idx = args.index("-report")
args.pop(r_idx)
reportfile = args.pop(r_idx)
else:
reportfile = None

if "-cache" in args:
c_idx = args.index("-cache")
c_dir = args[c_idx + 1]
Expand All @@ -513,11 +529,18 @@ def run_kubeconform(args, input):
]
+ args,
input=input,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
capture_output=True
)

# Report to separate file
if reportfile:
try:
with open(reportfile, "w") as f:
print(result.stdout, file=f)
except Exception as e:
raise Exception("can't write to file %s : %s" % reportfile, e)

# Check for errors
if result.returncode != 0:
raise Exception(
Expand Down