From 164720f27e4adc484951197abce99fdbf3d3e78f Mon Sep 17 00:00:00 2001 From: JGStew Date: Mon, 21 Oct 2024 14:24:10 -0400 Subject: [PATCH] add delete command, improve import command --- src/bescli/bescli.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/bescli/bescli.py b/src/bescli/bescli.py index 115b224..68b8be5 100644 --- a/src/bescli/bescli.py +++ b/src/bescli/bescli.py @@ -54,6 +54,9 @@ def __init__(self, **kwargs): def do_get(self, line): """Perform get request to BigFix server using provided api endpoint argument""" + # remove any extra whitespace + line = line.strip() + # Remove root server prefix: # if root server prefix is not removed # and root server is given as IP Address, @@ -80,6 +83,26 @@ def do_get(self, line): else: self.pfeedback("Not currently logged in. Type 'login'.") + def do_delete(self, line): + """Perform delete request to BigFix server using provided api endpoint argument""" + + # remove any extra whitespace + line = line.strip() + + # Remove root server prefix: + if "/api/" in line: + line = str(line).split("/api/", 1)[1] + self.pfeedback("get " + line) + + if self.bes_conn: + output_item = self.bes_conn.delete(line) + + print(output_item) + # print(output_item.besdict) + # print(output_item.besjson) + else: + self.pfeedback("Not currently logged in. Type 'login'.") + def do_post(self, statement): """post file as data to path""" print(statement) @@ -366,9 +389,13 @@ def do_export_all_sites(self, statement=None): def do_import_bes(self, statement): """import bes file""" - self.poutput(f"Import file: {statement.args}") + bes_file_path = str(statement.args).strip() + + site_path = self.bes_conn.get_current_site_path(None) + + self.poutput(f"Import file: {bes_file_path}") - self.poutput(self.bes_conn.import_bes_to_site(str(statement.args))) + self.poutput(self.bes_conn.import_bes_to_site(bes_file_path, site_path)) complete_upload = Cmd.path_complete