Skip to content

Commit

Permalink
Merge pull request #1290 from Keeper-Security/DR-667_clear_jobs_and_i…
Browse files Browse the repository at this point in the history
…tem_count

DR-667 Fix problem with item count and now automatically remove finis…
  • Loading branch information
jwalstra-keeper authored Aug 7, 2024
2 parents 6332673 + 4b5e586 commit 43e8f67
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
25 changes: 21 additions & 4 deletions keepercommander/commands/discover/result_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

if TYPE_CHECKING:
from ...params import KeeperParams
from ...vault import TypedRecord
from ...vault import TypedRecord, KeeperRecord
from keeper_dag.vertex import DAGVertex
from discovery_common.record_link import RecordLink

Expand Down Expand Up @@ -443,14 +443,16 @@ def _prompt(self,
break

elif command == "i":

print(f"{pad}{bcolors.OKBLUE}Creating an ignore rule for record.{bcolors.ENDC}")
return PromptResult(
action=PromptActionEnum.IGNORE,
acl=acl,
content=content
)

elif command == "s":
print(f"{pad}{bcolors.OKBLUE}Skipping record{bcolors.ENDC}")
print(f"{pad}{bcolors.OKBLUE}Skipping record.{bcolors.ENDC}")

return PromptResult(
action=PromptActionEnum.SKIP,
Expand Down Expand Up @@ -654,7 +656,7 @@ def _handle_admin_record_from_record(record: TypedRecord, content: DiscoveryObje
shared_folders = gateway_context.get_shared_folders(params)
if len(shared_folders) == 0:
while True:
yn = input(f"Create a PAM User record from {record.title}? [Y/N]>").lower()
yn = input(f"Create a PAM User record from {record.title}? [Y/N]> ").lower()
if yn == "":
continue
elif yn[0] == "n":
Expand All @@ -669,7 +671,7 @@ def _handle_admin_record_from_record(record: TypedRecord, content: DiscoveryObje
while True:
afq = input(f"({_b('A')})dd user to {folder_name}, "
f"Add user to ({_b('F')})older, "
f"({_b('Q')})uit >").lower()
f"({_b('Q')})uit > ").lower()
if afq == "":
continue
if afq[0] == "a":
Expand Down Expand Up @@ -1068,6 +1070,17 @@ def _get_directory_info(domain: str,

return directory_info

@staticmethod
def remove_job(params: KeeperParams, configuration_record: KeeperRecord, job_id: str):

try:
jobs = Jobs(record=configuration_record, params=params)
jobs.cancel(job_id)
print(f"{bcolors.OKGREEN}No items left to process. Removing completed discovery job.{bcolors.ENDC}")
except Exception as err:
logging.error(err)
print(f"{bcolors.FAIL}No items left to process. Failed to remove discovery job.{bcolors.ENDC}")

def execute(self, params: KeeperParams, **kwargs):

if not hasattr(params, 'pam_controllers'):
Expand Down Expand Up @@ -1178,11 +1191,15 @@ def execute(self, params: KeeperParams, **kwargs):
f"failure{'s' if results.failure_count != 1 else ''}.{bcolors.ENDC}")
for fail in results.failure:
print(f" * {fail.title}: {fail.error}")

if process.no_items_left is True:
self.remove_job(params=params, configuration_record=configuration_record, job_id=job_id)
else:
print(f"{bcolors.FAIL}No records have been added.{bcolors.ENDC}")

except NoDiscoveryDataException:
print(f"{bcolors.OKGREEN}All items have been added for this discovery job.{bcolors.ENDC}")
self.remove_job(params=params, configuration_record=configuration_record, job_id=job_id)

except Exception as err:
print(f"{bcolors.FAIL}Could not process discovery: {err}{bcolors.ENDC}")
Expand Down
27 changes: 17 additions & 10 deletions keepercommander/commands/pam_debug/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from ...params import KeeperParams



class PAMDebugGraphCommand(PAMGatewayActionDiscoverCommandBase):
parser = argparse.ArgumentParser(prog='dr-pam-command-debug')

Expand Down Expand Up @@ -72,11 +71,14 @@ def _do_text_list_infra(self, params: KeeperParams, gateway_context: GatewayCont

infra = Infrastructure(record=gateway_context.configuration, params=params, logger=logging,
debug_level=debug_level)
infra.load(sync_point=0)

try:
configuration = infra.get_root.has_vertices()[0]
except (Exception,):
print(f"{bcolors.FAIL}Could not find the configuration in the infrastructure graph.{bcolors.ENDC}")
print(f"{bcolors.FAIL}Could not find the configuration in the infrastructure graph. "
f"Has discovery been run for this gateway?{bcolors.ENDC}")

return

line_start = {
Expand Down Expand Up @@ -104,15 +106,20 @@ def _handle(current_vertex: DAGVertex, indent: int = 0, last_record_type: Option
ls = line_start.get(indent, " ")
cf = color_func.get(indent, self._p)

current_content = DiscoveryObject.get_discovery_object(current_vertex)
if current_content.record_uid is None:
text += f"{pad}{ls}{current_content.title} does not have a record."
if current_vertex.corrupt is False:
current_content = DiscoveryObject.get_discovery_object(current_vertex)
if current_content.record_uid is None:
text += f"{pad}{ls}{current_content.title} does not have a record."
else:
record = vault.KeeperRecord.load(params, current_content.record_uid) # type: Optional[TypedRecord]
if record is not None:
text += f"{pad}{ls}" + cf(f"{record.title}; {record.record_uid}")
else:
text += f"{pad}{ls}" + cf(f"{current_content.title}; " +
self._f("have record uid, record does not exists, "
"might have to sync."))
else:
record = vault.KeeperRecord.load(params, current_content.record_uid) # type: Optional[TypedRecord]
text += f"{pad}{ls}" + cf(f"{record.title}; {record.record_uid}")

if current_vertex.active is False:
text += " " + self._f("Inactive")
text += f"{pad}{current_vertex.uid} " + self._f("(Corrupt)")

print(text)

Expand Down
Binary file modified libs/discovery_common-1.0.10-py3-none-any.whl
Binary file not shown.
Binary file modified libs/keeper_dag-1.0.10-py3-none-any.whl
Binary file not shown.

0 comments on commit 43e8f67

Please sign in to comment.