forked from OpenCTI-Platform/client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopencti_api_work.py
82 lines (74 loc) · 2.79 KB
/
opencti_api_work.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import logging
class OpenCTIApiWork:
"""OpenCTIApiJob"""
def __init__(self, api):
self.api = api
def to_received(self, work_id: str, message: str):
logging.info("Reporting work update_received " + work_id)
query = """
mutation workToReceived($id: ID!, $message: String) {
workEdit(id: $id) {
toReceived (message: $message) {
id
}
}
}
"""
self.api.query(query, {"id": work_id, "message": message})
def to_processed(self, work_id: str, message: str, in_error: bool = False):
logging.info("Reporting work update_received " + work_id)
query = """
mutation workToProcessed($id: ID!, $message: String, $inError: Boolean) {
workEdit(id: $id) {
toProcessed (message: $message, inError: $inError) {
id
}
}
}
"""
self.api.query(query, {"id": work_id, "message": message, "inError": in_error})
def report_expectation(self, work_id: str, error):
logging.info("Report expectation for " + work_id)
query = """
mutation reportExpectation($id: ID!, $error: WorkErrorInput) {
workEdit(id: $id) {
reportExpectation(error: $error) {
id
}
}
}
"""
try:
self.api.query(query, {"id": work_id, "error": error})
except:
self.api.log("error", "Cannot report expectation")
def add_expectations(self, work_id: str, expectations: int):
logging.info(
"Update action expectations " + work_id + " - " + str(expectations)
)
query = """
mutation addExpectations($id: ID!, $expectations: Int) {
workEdit(id: $id) {
addExpectations(expectations: $expectations) {
id
}
}
}
"""
try:
self.api.query(query, {"id": work_id, "expectations": expectations})
except:
self.api.log("error", "Cannot report expectation")
def initiate_work(self, connector_id: str, friendly_name: str) -> str:
logging.info("Initiate work for " + connector_id)
query = """
mutation workAdd($connectorId: String!, $friendlyName: String) {
workAdd(connectorId: $connectorId, friendlyName: $friendlyName) {
id
}
}
"""
work = self.api.query(
query, {"connectorId": connector_id, "friendlyName": friendly_name}
)
return work["data"]["workAdd"]["id"]