Skip to content

Commit d14aa56

Browse files
authored
Merge pull request #62 from JupiterOne/TD-7293
migrate UPDATE_RELATIONSHIPV2 to UPDATE_RELATIONSHIP - 2.0.0 major re…
2 parents 09814e3 + 9053d45 commit d14aa56

File tree

6 files changed

+157
-56
lines changed

6 files changed

+157
-56
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ j1.create_relationship(
246246
# Basic relationship update
247247
j1.update_relationship(
248248
relationship_id='<id-of-relationship-to-update>',
249+
from_entity_id='<id-of-source-entity>',
250+
to_entity_id='<id-of-destination-entity>',
249251
properties={
250252
"<relationship-property-name>": "<relationship-property-updated-value>",
251253
},
@@ -254,6 +256,8 @@ j1.update_relationship(
254256
# Update relationship with complex properties
255257
j1.update_relationship(
256258
relationship_id='<id-of-relationship-to-update>',
259+
from_entity_id='<id-of-source-entity>',
260+
to_entity_id='<id-of-destination-entity>',
257261
properties={
258262
'accessLevel': 'write',
259263
'lastModified': int(time.time()) * 1000,
@@ -265,12 +269,25 @@ j1.update_relationship(
265269
# Update relationship with tags
266270
j1.update_relationship(
267271
relationship_id='<id-of-relationship-to-update>',
272+
from_entity_id='<id-of-source-entity>',
273+
to_entity_id='<id-of-destination-entity>',
268274
properties={
269275
'tag.Status': 'active',
270276
'tag.Priority': 'high',
271277
'tag.ReviewRequired': 'true'
272278
}
273279
)
280+
281+
# Update relationship with custom timestamp
282+
j1.update_relationship(
283+
relationship_id='<id-of-relationship-to-update>',
284+
from_entity_id='<id-of-source-entity>',
285+
to_entity_id='<id-of-destination-entity>',
286+
properties={
287+
'lastUpdated': int(time.time()) * 1000
288+
},
289+
timestamp=int(time.time()) * 1000 # Custom timestamp
290+
)
274291
```
275292

276293
##### Delete a relationship

examples/03_relationship_management.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def create_relationship_examples(j1, from_entity_id, to_entity_id):
113113

114114
return basic_relationship, relationship_with_props, complex_relationship
115115

116-
def update_relationship_examples(j1, relationship_id):
116+
def update_relationship_examples(j1, relationship_id, from_entity_id, to_entity_id):
117117
"""Demonstrate relationship update operations."""
118118

119119
print("=== Relationship Update Examples ===\n")
@@ -122,6 +122,8 @@ def update_relationship_examples(j1, relationship_id):
122122
print("1. Updating basic relationship properties:")
123123
basic_update = j1.update_relationship(
124124
relationship_id=relationship_id,
125+
from_entity_id=from_entity_id,
126+
to_entity_id=to_entity_id,
125127
properties={
126128
'accessLevel': 'write',
127129
'lastModified': int(time.time()) * 1000
@@ -133,6 +135,8 @@ def update_relationship_examples(j1, relationship_id):
133135
print("2. Updating with complex properties:")
134136
j1.update_relationship(
135137
relationship_id=relationship_id,
138+
from_entity_id=from_entity_id,
139+
to_entity_id=to_entity_id,
136140
properties={
137141
'accessLevel': 'admin',
138142
'lastModified': int(time.time()) * 1000,
@@ -151,6 +155,8 @@ def update_relationship_examples(j1, relationship_id):
151155
print("3. Updating relationship tags:")
152156
j1.update_relationship(
153157
relationship_id=relationship_id,
158+
from_entity_id=from_entity_id,
159+
to_entity_id=to_entity_id,
154160
properties={
155161
'tag.Status': 'active',
156162
'tag.Priority': 'high',
@@ -159,6 +165,19 @@ def update_relationship_examples(j1, relationship_id):
159165
}
160166
)
161167
print(f"Updated relationship tags\n")
168+
169+
# 4. Update with custom timestamp
170+
print("4. Updating with custom timestamp:")
171+
j1.update_relationship(
172+
relationship_id=relationship_id,
173+
from_entity_id=from_entity_id,
174+
to_entity_id=to_entity_id,
175+
properties={
176+
'lastUpdated': int(time.time()) * 1000
177+
},
178+
timestamp=int(time.time()) * 1000 # Custom timestamp
179+
)
180+
print(f"Updated with custom timestamp\n")
162181

163182
def delete_relationship_examples(j1, relationship_id):
164183
"""Demonstrate relationship deletion."""
@@ -366,7 +385,7 @@ def main():
366385
basic_rel, props_rel, complex_rel = create_relationship_examples(j1, from_entity_id, to_entity_id)
367386

368387
# Update examples (using the relationship with properties)
369-
update_relationship_examples(j1, props_rel['relationship']['_id'])
388+
update_relationship_examples(j1, props_rel['relationship']['_id'], from_entity_id, to_entity_id)
370389

371390
# Complete lifecycle example
372391
relationship_lifecycle_example(j1, from_entity_id, to_entity_id)

jupiterone/client.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
DELETE_ENTITY,
2525
UPDATE_ENTITY,
2626
CREATE_RELATIONSHIP,
27-
UPDATE_RELATIONSHIPV2,
27+
UPDATE_RELATIONSHIP,
2828
DELETE_RELATIONSHIP,
2929
CURSOR_QUERY_V1,
3030
DEFERRED_RESPONSE_QUERY,
@@ -552,21 +552,21 @@ def update_relationship(self, **kwargs) -> Dict:
552552
553553
args:
554554
relationship_id (str): Unique _id of the relationship
555+
from_entity_id (str): Unique _id of the source entity
556+
to_entity_id (str): Unique _id of the target entity
555557
properties (dict): Dictionary of key/value relationship properties
558+
timestamp (int, optional): Timestamp for the update (defaults to current time)
556559
"""
557-
now_dt = datetime.now()
558-
559560
variables = {
560-
"relationship": {"_id": kwargs.pop("relationship_id")},
561-
"timestamp": int(datetime.now().timestamp() * 1000),
561+
"relationshipId": kwargs.pop("relationship_id"),
562+
"fromEntityId": kwargs.pop("from_entity_id"),
563+
"toEntityId": kwargs.pop("to_entity_id"),
564+
"timestamp": kwargs.pop("timestamp", int(datetime.now().timestamp() * 1000)),
565+
"properties": kwargs.pop("properties", None)
562566
}
563567

564-
properties = kwargs.pop("properties", None)
565-
if properties:
566-
variables["relationship"].update(properties)
567-
568-
response = self._execute_query(query=UPDATE_RELATIONSHIPV2, variables=variables)
569-
return response["data"]["updateRelationshipV2"]
568+
response = self._execute_query(query=UPDATE_RELATIONSHIP, variables=variables)
569+
return response["data"]["updateRelationship"]
570570

571571
def delete_relationship(self, relationship_id: str = None):
572572
"""Deletes a relationship between two entities.

jupiterone/constants.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,36 @@
8383
}
8484
}
8585
"""
86-
UPDATE_RELATIONSHIPV2 = """
87-
mutation UpdateRelationshipV2 (
88-
$relationship: JSON!
86+
UPDATE_RELATIONSHIP = """
87+
mutation UpdateRelationship(
88+
$relationshipId: String!
89+
$fromEntityId: String!
90+
$toEntityId: String!
8991
$timestamp: Long
92+
$properties: JSON
9093
) {
91-
updateRelationshipV2 (
92-
relationship: $relationship,
94+
updateRelationship(
95+
relationshipId: $relationshipId,
96+
fromEntityId: $fromEntityId,
97+
toEntityId: $toEntityId,
9398
timestamp: $timestamp,
99+
properties: $properties
94100
) {
95-
relationship
101+
relationship {
102+
_id
103+
_key
104+
_type
105+
_class
106+
_fromEntityId
107+
_toEntityId
108+
displayName
109+
}
110+
edge {
111+
id
112+
fromVertexId
113+
toVertexId
114+
properties
115+
}
96116
}
97117
}
98118
"""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="jupiterone",
8-
version="1.7.0",
8+
version="2.0.0",
99
description="A Python client for the JupiterOne API",
1010
license="MIT License",
1111
author="JupiterOne",

0 commit comments

Comments
 (0)