Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Metadata,
VisualFamily,
Workflow,
WorkflowTypes,
)

if TYPE_CHECKING:
Expand All @@ -37,6 +38,7 @@

INTEGRATIONS_PATH = "Integrations"
PLAYBOOKS_PATH = "Playbooks"
BLOCKS_PATH = "Blocks"
CONNECTORS_PATH = "Connectors"
JOBS_PATH = "Jobs"
MAPPINGS_PATH = "Ontology/Mappings"
Expand Down Expand Up @@ -142,6 +144,9 @@ def get_playbook(self, playbook_name: str) -> Workflow | None:
for playbook in self.git.get_file_objects_from_path(PLAYBOOKS_PATH):
if playbook.path.endswith(f"/{playbook_name}.json"):
return Workflow(json.loads(playbook.content))
for block in self.git.get_file_objects_from_path(BLOCKS_PATH):
if block.path.endswith(f"/{playbook_name}.json"):
return Workflow(json.loads(block.content))
except KeyError:
return None

Expand All @@ -150,6 +155,9 @@ def get_playbooks(self) -> list[Workflow]:
for playbook in self.git.get_file_objects_from_path(PLAYBOOKS_PATH):
if playbook.path.endswith(".json"):
yield Workflow(json.loads(playbook.content))
for block in self.git.get_file_objects_from_path(BLOCKS_PATH):
if block.path.endswith(".json"):
yield Workflow(json.loads(block.content))
except KeyError:
return []

Expand Down Expand Up @@ -341,6 +349,20 @@ def push_playbook(self, playbook: Workflow) -> None:
f"{PLAYBOOKS_PATH}/{playbook.category}/{playbook.name}",
)

def push_block(self, block: Workflow) -> None:
"""Writes a block to the repo

Args:
block: A block object

"""
self._push_obj(
block,
block.name,
"Block",
f"{BLOCKS_PATH}/{block.category}/{block.name}",
)

def push_connector(self, connector: Connector) -> None:
"""Writes a connector instance to the repo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@
from soar_sdk.SiemplifyLogger import SiemplifyLogger


PUSH_FAILURE_INDICATORS = (
"pre-receive hook declined",
"not allowed to push",
"push rejected",
"failed to push",
"error: failed to push",
"! [rejected]",
"! [remote rejected]",
)

class Git:
"""GitManager"""

Expand Down Expand Up @@ -232,26 +222,13 @@ def push(self, force_push=False) -> None:
equivalent to 'git push --force'. Defaults to False.

"""
error_content = ""
try:
error_buffer = StringIO()
tee_stream = TeeStream(sys.stderr, error_buffer)

try:
porcelain.push(
self.repo,
refspecs=[self.local_branch_ref],
force=force_push,
errstream=tee_stream,
**self.connection_args,
)
finally:
tee_stream.flush()
error_content = error_buffer.getvalue().strip()
tee_stream.close()

self._raise_on_push_errors(error_content)

porcelain.push(
self.repo,
refspecs=[self.local_branch_ref],
force=force_push,
**self.connection_args,
)
except porcelain.DivergedBranches:
self.logger.error("Could not push updates to remote repository!")
self.logger.warn(
Expand All @@ -264,15 +241,6 @@ def push(self, force_push=False) -> None:
"Updates will be pushed in the next python script execution",
)

def _raise_on_push_errors(self, error_content: str |None) -> None:
"""Check for push failure indicators and raise exception."""
if not error_content:
return

if any(indicator in error_content for indicator in PUSH_FAILURE_INDICATORS):
self.logger.error(f"Push operation failed: {error_content}")
raise GitSyncException(f"Push operation failed: {error_content}")

def _checkout(self) -> None:
"""Checkout a branch

Expand Down Expand Up @@ -805,4 +773,4 @@ def _verify_and_decide(self, client, hostname, key) -> None:
else:
self.vendor.siemplify_logger.error("Fingerprint verification failed.")
raise paramiko.ssh_exception.SSHException(
f"Host key verification failed for {hostname}")
f"Host key verification failed for {hostname}")
Loading
Loading