Skip to content

Commit

Permalink
add fetch_integration_jobs and fetch_integration_job_events
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaBlooms committed Aug 29, 2024
1 parent acd8868 commit 99d031a
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 4 deletions.
40 changes: 36 additions & 4 deletions jupiterone/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
DELETE_RELATIONSHIP,
CURSOR_QUERY_V1,
CREATE_INSTANCE,
INTEGRATION_JOB_VALUES,
INTEGRATION_INSTANCE_EVENT_VALUES,
ALL_PROPERTIES,
CREATE_SMARTCLASS,
CREATE_SMARTCLASS_QUERY,
EVALUATE_SMARTCLASS,
GET_SMARTCLASS_DETAILS
GET_SMARTCLASS_DETAILS,
)


Expand Down Expand Up @@ -240,7 +242,7 @@ def _limit_and_skip_query(

return {"data": results}

def _execute_syncapi_request(self, endpoint: str, payload: Dict):
def _execute_syncapi_request(self, endpoint: str, payload: Dict = None) -> Dict:

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
"""Executes POST request to SyncAPI endpoints"""

# initiate requests session and implement retry logic of 5 request retries with 1 second between
Expand All @@ -266,7 +268,6 @@ def _execute_syncapi_request(self, endpoint: str, payload: Dict):
"JupiterOne API rate limit exceeded"
)
raise JupiterOneApiError(content.get("errors"))

return response.json()

elif response.status_code == 401:
Expand Down Expand Up @@ -518,14 +519,45 @@ def finalize_sync_job(self, instance_job_id: str = None):

return response

def fetch_integration_jobs(self, instance_id: str = None):
"""Fetch Integration Job details from defined integration instance.
args:
instance_id (str): The "integrationInstanceId" of the integration to fetch jobs from.
"""
variables = {
"integrationInstanceId": instance_id,
"size": 100
}

response = self._execute_query(INTEGRATION_JOB_VALUES, variables=variables)

return response['data']['integrationJobs']

def fetch_integration_job_events(self, instance_id: str = None, instance_job_id: str = None):
"""Fetch events within an integration job run.
args:
instance_id (str): The integration Instance Id of the integration to fetch job events from.
instance_job_id (str): The integration Job ID of the integration to fetch job events from.
"""
variables = {
"integrationInstanceId": instance_id,
"jobId": instance_job_id,
"size": 1000
}

response = self._execute_query(INTEGRATION_INSTANCE_EVENT_VALUES, variables=variables)

return response['data']['integrationEvents']

def create_smartclass(self, smartclass_name: str = None, smartclass_description: str = None):
"""Creates a new Smart Class within Assets.
args:
smartclass_name (str): The "Smart class name" for Smart Class to be created.
smartclass_description (str): The "Description" for Smart Class to be created.
"""

variables = {
"input": {
"tagName": smartclass_name,
Expand Down
79 changes: 79 additions & 0 deletions jupiterone/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,82 @@
}
}
"""

INTEGRATION_JOB_VALUES = """
query IntegrationJobs(
$status: IntegrationJobStatus
$integrationInstanceId: String
$integrationDefinitionId: String
$integrationInstanceIds: [String]
$cursor: String
$size: Int
) {
integrationJobs(
status: $status
integrationInstanceId: $integrationInstanceId
integrationDefinitionId: $integrationDefinitionId
integrationInstanceIds: $integrationInstanceIds
cursor: $cursor
size: $size
) {
jobs {
id
status
integrationInstanceId
createDate
endDate
hasSkippedSteps
integrationInstance {
id
name
__typename
}
integrationDefinition {
id
title
integrationType
__typename
}
__typename
}
pageInfo {
endCursor
__typename
}
__typename
}
}
"""

INTEGRATION_INSTANCE_EVENT_VALUES = """
query ListEvents(
$jobId: String!
$integrationInstanceId: String!
$cursor: String
$size: Int
) {
integrationEvents(
size: $size
cursor: $cursor
jobId: $jobId
integrationInstanceId: $integrationInstanceId
) {
events {
id
name
description
createDate
jobId
level
eventCode
__typename
}
pageInfo {
endCursor
hasNextPage
__typename
}
__typename
}
}
"""

0 comments on commit 99d031a

Please sign in to comment.