Skip to content

Commit 6b76fbe

Browse files
authored
Merge pull request #27 from JupiterOne/KNO-454
1.1.0 add additional methods
2 parents f017fd2 + 87232e7 commit 6b76fbe

File tree

6 files changed

+856
-11
lines changed

6 files changed

+856
-11
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ For users with J1 accounts in the EU region, the 'url' parameter will need to be
3030

3131
If no 'url' parameter is passed, the default of "https://graphql.us.jupiterone.io" is used.
3232

33+
##### Method Exmaples:
34+
35+
See the examples/examples.py for full usage example documentation
36+
3337
##### Execute a query:
3438

3539
```python

examples/exampleEntitiesRelated.png

149 KB
Loading

examples/examples.py

Lines changed: 201 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
account = os.environ.get("JUPITERONE_ACCOUNT")
77
token = os.environ.get("JUPITERONE_TOKEN")
8+
url = "https://graphql.us.jupiterone.io"
89

9-
j1 = JupiterOneClient(account=account, token=token)
10+
j1 = JupiterOneClient(account=account, token=token, url=url)
1011

1112
# query_v1
1213
q = "FIND jupiterone_user"
1314
query_r = j1.query_v1(q)
15+
print("query_v1()")
1416
print(query_r)
1517

1618
# create_entity
@@ -31,6 +33,7 @@
3133
properties=properties,
3234
timestamp=int(time.time()) * 1000 # Optional, defaults to current datetime
3335
)
36+
print("create_entity()")
3437
print(create_r)
3538

3639
properties = {
@@ -42,6 +45,7 @@
4245
entity_id='{}'.format(create_r['entity']['_id']),
4346
properties=properties
4447
)
48+
print("update_entity()")
4549
print(update_r)
4650

4751
# create_entity_2
@@ -61,6 +65,7 @@
6165
properties=properties,
6266
timestamp=int(time.time()) * 1000 # Optional, defaults to current datetime
6367
)
68+
print("create_entity()")
6469
print(create_r_2)
6570

6671
# create_relationship
@@ -71,20 +76,214 @@
7176
from_entity_id=create_r['entity']['_id'],
7277
to_entity_id=create_r_2['entity']['_id'],
7378
)
79+
print("create_relationship()")
7480
print(create_relationship_r)
7581

7682
# delete_relationship
7783
delete_relationship_r = j1.delete_relationship(relationship_id=create_relationship_r['relationship']['_id'])
84+
print("delete_relationship()")
7885
print(delete_relationship_r)
7986

8087
# delete_entity
8188
delete_entity_r1 = j1.delete_entity(entity_id=create_r['entity']['_id'])
89+
print("delete_entity()")
8290
print(delete_entity_r1)
8391

8492
delete_entity_r2 = j1.delete_entity(entity_id=create_r_2['entity']['_id'])
93+
print("delete_entity()")
8594
print(delete_entity_r2)
8695

96+
# cursor_query
8797
q = "FIND Person"
8898
cursor_query_r = j1._cursor_query(q)
99+
print("cursor_query()")
89100
print(cursor_query_r)
90-
print(len(cursor_query_r['data']))
101+
102+
# fetch_all_entity_properties
103+
fetch_all_entity_properties_r = j1.fetch_all_entity_properties()
104+
print("fetch_all_entity_properties()")
105+
print(fetch_all_entity_properties_r)
106+
107+
# fetch_all_entity_tags
108+
fetch_all_entity_tags_r = j1.fetch_all_entity_tags()
109+
print("fetch_all_entity_tags()")
110+
print(fetch_all_entity_tags_r)
111+
112+
# create_integration_instance
113+
create_integration_instance_r = j1.create_integration_instance(instance_name="pythonclient-customintegration",
114+
instance_description="dev-testing")
115+
print("create_integration_instance()")
116+
print(create_integration_instance_r)
117+
118+
integration_instance_id = "<GUID>"
119+
120+
# start_sync_job
121+
start_sync_job_r = j1.start_sync_job(instance_id=integration_instance_id)
122+
print("start_sync_job()")
123+
print(start_sync_job_r)
124+
125+
# upload_entities_batch_json
126+
entity_payload = [
127+
{
128+
"_key": "1",
129+
"_type": "pythonclient",
130+
"_class": "API",
131+
"displayName": "pythonclient1",
132+
"propertyName": "value",
133+
"relationshipProperty": "source",
134+
},
135+
{
136+
"_key": "2",
137+
"_type": "pythonclient",
138+
"_class": "API",
139+
"displayName": "pythonclient2",
140+
"propertyName": "value"
141+
},
142+
{
143+
"_key": "3",
144+
"_type": "pythonclient",
145+
"_class": "API",
146+
"displayName": "pythonclient3",
147+
"propertyName": "value"
148+
}
149+
]
150+
151+
# update_entities_batch_json
152+
upload_entities_batch_json_r = j1.upload_entities_batch_json(instance_job_id=start_sync_job_r['job']['id'],
153+
entities_list=entity_payload)
154+
print("upload_entities_batch_json()")
155+
print(upload_entities_batch_json_r)
156+
157+
# upload_relationships_batch_json
158+
relationships_payload = [
159+
{
160+
"_key": "1:2",
161+
"_class": "EXTENDS",
162+
"_type": "pythonclient_extends_pythonclient",
163+
"_fromEntityKey": "1",
164+
"_toEntityKey": "2",
165+
"relationshipProperty": "value"
166+
},
167+
{
168+
"_key": "2:3",
169+
"_class": "EXTENDS",
170+
"_type": "pythonclient_extends_pythonclient",
171+
"_fromEntityKey": "2",
172+
"_toEntityKey": "3",
173+
"relationshipProperty": "value"
174+
}
175+
]
176+
177+
# update_relationships_batch_json
178+
upload_relationships_batch_json_r = j1.upload_relationships_batch_json(instance_job_id=start_sync_job_r['job']['id'],
179+
relationships_list=relationships_payload)
180+
print("upload_relationships_batch_json()")
181+
print(upload_relationships_batch_json_r)
182+
183+
# upload_entities_batch_json
184+
combined_payload = {
185+
"entities": [
186+
{
187+
"_key": "4",
188+
"_type": "pythonclient",
189+
"_class": "API",
190+
"displayName": "pythonclient4",
191+
"propertyName": "value",
192+
"relationshipProperty": "source",
193+
},
194+
{
195+
"_key": "5",
196+
"_type": "pythonclient",
197+
"_class": "API",
198+
"displayName": "pythonclient5",
199+
"propertyName": "value"
200+
},
201+
{
202+
"_key": "6",
203+
"_type": "pythonclient",
204+
"_class": "API",
205+
"displayName": "pythonclient6",
206+
"propertyName": "value"
207+
}
208+
],
209+
"relationships": [
210+
{
211+
"_key": "4:5",
212+
"_class": "EXTENDS",
213+
"_type": "pythonclient_extends_pythonclient",
214+
"_fromEntityKey": "4",
215+
"_toEntityKey": "5",
216+
"relationshipProperty": "value"
217+
},
218+
{
219+
"_key": "5:6",
220+
"_class": "EXTENDS",
221+
"_type": "pythonclient_extends_pythonclient",
222+
"_fromEntityKey": "5",
223+
"_toEntityKey": "6",
224+
"relationshipProperty": "value"
225+
}
226+
]
227+
}
228+
229+
# upload_combined_batch_json
230+
upload_combined_batch_json_r = j1.upload_combined_batch_json(instance_job_id=start_sync_job_r['job']['id'],
231+
combined_payload=combined_payload)
232+
print("upload_combined_batch_json()")
233+
print(upload_combined_batch_json_r)
234+
235+
# finalize_sync_job
236+
finalize_sync_job_r = j1.finalize_sync_job(instance_job_id=start_sync_job_r['job']['id'])
237+
print("finalize_sync_job()")
238+
print(finalize_sync_job_r)
239+
240+
# fetch_integration_jobs
241+
fetch_integration_jobs_r = j1.fetch_integration_jobs(instance_id=integration_instance_id)
242+
print("fetch_integration_jobs()")
243+
print(fetch_integration_jobs_r)
244+
245+
while j1.fetch_integration_jobs(instance_id=integration_instance_id)['jobs'][0]['status'] == "IN_PROGRESS":
246+
247+
fetch_integration_jobs_r = j1.fetch_integration_jobs(instance_id=integration_instance_id)
248+
249+
print("fetch_integration_jobs()")
250+
print(fetch_integration_jobs_r)
251+
252+
# fetch_integration_job_events
253+
fetch_integration_job_events_r = j1.fetch_integration_job_events(instance_id=integration_instance_id,
254+
instance_job_id=fetch_integration_jobs_r['jobs'][0]['id'])
255+
print("fetch_integration_job_events()")
256+
print(fetch_integration_job_events_r)
257+
258+
# create_smartclass
259+
create_smartclass_r = j1.create_smartclass(smartclass_name="SmartClass1",
260+
smartclass_description="Created via create_smartclass() method")
261+
print("create_smartclass()")
262+
print(create_smartclass_r)
263+
264+
# create_smartclass_query
265+
create_smartclass_query_r = j1.create_smartclass_query(smartclass_id=create_smartclass_r['id'],
266+
query="FIND (Device|Host) with osType ~= \'Windows\'",
267+
query_description="all windows devices and hosts")
268+
print("create_smartclass_query()")
269+
print(create_smartclass_query_r)
270+
271+
# evaluate_smartclass
272+
evaluate_smartclass_r = j1.evaluate_smartclass(smartclass_id=create_smartclass_query_r['smartClassId'])
273+
print("evaluate_smartclass()")
274+
print(evaluate_smartclass_r)
275+
276+
# get_smartclass_details
277+
get_smartclass_details_r = j1.get_smartclass_details(smartclass_id=create_smartclass_query_r['smartClassId'])
278+
print("get_smartclass_details()")
279+
print(get_smartclass_details_r)
280+
281+
# list_configured_alert_rules
282+
list_configured_alert_rules_r = j1.list_configured_alert_rules()
283+
print("list_configured_alert_rules()")
284+
print(list_configured_alert_rules_r)
285+
286+
# generate_j1ql
287+
generate_j1ql_r = j1.generate_j1ql(natural_language_prompt="show me all Users containing 'jupiterone' in their email address")
288+
print("generate_j1ql()")
289+
print(generate_j1ql_r)

0 commit comments

Comments
 (0)