Skip to content

Commit db402eb

Browse files
NVSHAS-10048: Support exporting/importing response rules in cli
1 parent d63918b commit db402eb

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

cli/prog/system.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,40 @@ def request_export_admission(data, config, id, filename, remote_repository_nickn
14171417
click.echo(respData)
14181418
return
14191419

1420+
@request_export.command('response')
1421+
@click.option("--id", multiple=True, help="ID of response rule to export")
1422+
@click.option("--filename", "-f", type=click.Path(dir_okay=False, writable=True, resolve_path=True), help="Local file path when export to local machine")
1423+
@click.option("--remote_repository_nickname", default="default", help="Repository nickname when export to remote repository")
1424+
@click.option("--remote_filepath", default="", help="File path on repository when export to remote repository")
1425+
@click.option("--comment", default="", help="Comment for export to remote repository")
1426+
@click.pass_obj
1427+
def request_export_response(data, id, filename, remote_repository_nickname, remote_filepath, comment):
1428+
"""Export non-group-dependent response rules."""
1429+
1430+
ids = []
1431+
for n in id:
1432+
ids.append(int(n))
1433+
1434+
payload = {"ids": ids}
1435+
remote_export_options, useRemote, ok = validate_export_filepath(filename, remote_repository_nickname, remote_filepath)
1436+
if ok:
1437+
if useRemote:
1438+
payload["remote_export_options"] = remote_export_options
1439+
else:
1440+
return
1441+
1442+
respData = data.client.requestDownload("file", "response/rule", None, payload)
1443+
if filename and len(filename) > 0:
1444+
try:
1445+
with click.open_file(filename, 'w') as wfp:
1446+
wfp.write(respData)
1447+
click.echo("Wrote to %s" % click.format_filename(filename))
1448+
except IOError:
1449+
click.echo("Error: Failed to write to %s" % click.format_filename(filename))
1450+
else:
1451+
click.echo(respData)
1452+
return
1453+
14201454
@request_export.command('dlp')
14211455
@click.option("--name", multiple=True, help="Name of DLP sensor to export")
14221456
@click.option("--filename", "-f", type=click.Path(dir_okay=False, writable=True, resolve_path=True), help="Local file path when export to local machine")
@@ -1673,6 +1707,14 @@ def import_admission(data, filename):
16731707
"""Import admission control configuration/rules."""
16741708
import_function("file/admission/config", data, filename, "admission control configuration/rules")
16751709

1710+
@request_import.command('response')
1711+
@click.argument('filename', type=click.Path(dir_okay=False, exists=True, resolve_path=True))
1712+
# @click.option("--raw", default=False, is_flag=True, help="Upload in raw format")
1713+
@click.pass_obj
1714+
def import_response(data, filename):
1715+
"""Import non-group-dependent response rules."""
1716+
import_function("file/response/rule/config", data, filename, "non-group-dependent response rules")
1717+
16761718
@request_import.command('dlp')
16771719
@click.argument('filename', type=click.Path(dir_okay=False, exists=True, resolve_path=True))
16781720
@click.pass_obj

0 commit comments

Comments
 (0)