Skip to content
Merged
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ j1.create_relationship(
# Basic relationship update
j1.update_relationship(
relationship_id='<id-of-relationship-to-update>',
from_entity_id='<id-of-source-entity>',
to_entity_id='<id-of-destination-entity>',
properties={
"<relationship-property-name>": "<relationship-property-updated-value>",
},
Expand All @@ -254,6 +256,8 @@ j1.update_relationship(
# Update relationship with complex properties
j1.update_relationship(
relationship_id='<id-of-relationship-to-update>',
from_entity_id='<id-of-source-entity>',
to_entity_id='<id-of-destination-entity>',
properties={
'accessLevel': 'write',
'lastModified': int(time.time()) * 1000,
Expand All @@ -265,12 +269,25 @@ j1.update_relationship(
# Update relationship with tags
j1.update_relationship(
relationship_id='<id-of-relationship-to-update>',
from_entity_id='<id-of-source-entity>',
to_entity_id='<id-of-destination-entity>',
properties={
'tag.Status': 'active',
'tag.Priority': 'high',
'tag.ReviewRequired': 'true'
}
)

# Update relationship with custom timestamp
j1.update_relationship(
relationship_id='<id-of-relationship-to-update>',
from_entity_id='<id-of-source-entity>',
to_entity_id='<id-of-destination-entity>',
properties={
'lastUpdated': int(time.time()) * 1000
},
timestamp=int(time.time()) * 1000 # Custom timestamp
)
```

##### Delete a relationship
Expand Down
23 changes: 21 additions & 2 deletions examples/03_relationship_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def create_relationship_examples(j1, from_entity_id, to_entity_id):

return basic_relationship, relationship_with_props, complex_relationship

def update_relationship_examples(j1, relationship_id):
def update_relationship_examples(j1, relationship_id, from_entity_id, to_entity_id):
"""Demonstrate relationship update operations."""

print("=== Relationship Update Examples ===\n")
Expand All @@ -122,6 +122,8 @@ def update_relationship_examples(j1, relationship_id):
print("1. Updating basic relationship properties:")
basic_update = j1.update_relationship(
relationship_id=relationship_id,
from_entity_id=from_entity_id,
to_entity_id=to_entity_id,
properties={
'accessLevel': 'write',
'lastModified': int(time.time()) * 1000
Expand All @@ -133,6 +135,8 @@ def update_relationship_examples(j1, relationship_id):
print("2. Updating with complex properties:")
j1.update_relationship(
relationship_id=relationship_id,
from_entity_id=from_entity_id,
to_entity_id=to_entity_id,
properties={
'accessLevel': 'admin',
'lastModified': int(time.time()) * 1000,
Expand All @@ -151,6 +155,8 @@ def update_relationship_examples(j1, relationship_id):
print("3. Updating relationship tags:")
j1.update_relationship(
relationship_id=relationship_id,
from_entity_id=from_entity_id,
to_entity_id=to_entity_id,
properties={
'tag.Status': 'active',
'tag.Priority': 'high',
Expand All @@ -159,6 +165,19 @@ def update_relationship_examples(j1, relationship_id):
}
)
print(f"Updated relationship tags\n")

# 4. Update with custom timestamp
print("4. Updating with custom timestamp:")
j1.update_relationship(
relationship_id=relationship_id,
from_entity_id=from_entity_id,
to_entity_id=to_entity_id,
properties={
'lastUpdated': int(time.time()) * 1000
},
timestamp=int(time.time()) * 1000 # Custom timestamp
)
print(f"Updated with custom timestamp\n")

def delete_relationship_examples(j1, relationship_id):
"""Demonstrate relationship deletion."""
Expand Down Expand Up @@ -366,7 +385,7 @@ def main():
basic_rel, props_rel, complex_rel = create_relationship_examples(j1, from_entity_id, to_entity_id)

# Update examples (using the relationship with properties)
update_relationship_examples(j1, props_rel['relationship']['_id'])
update_relationship_examples(j1, props_rel['relationship']['_id'], from_entity_id, to_entity_id)

# Complete lifecycle example
relationship_lifecycle_example(j1, from_entity_id, to_entity_id)
Expand Down
22 changes: 11 additions & 11 deletions jupiterone/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
DELETE_ENTITY,
UPDATE_ENTITY,
CREATE_RELATIONSHIP,
UPDATE_RELATIONSHIPV2,
UPDATE_RELATIONSHIP,
DELETE_RELATIONSHIP,
CURSOR_QUERY_V1,
DEFERRED_RESPONSE_QUERY,
Expand Down Expand Up @@ -552,21 +552,21 @@ def update_relationship(self, **kwargs) -> Dict:

args:
relationship_id (str): Unique _id of the relationship
from_entity_id (str): Unique _id of the source entity
to_entity_id (str): Unique _id of the target entity
properties (dict): Dictionary of key/value relationship properties
timestamp (int, optional): Timestamp for the update (defaults to current time)
"""
now_dt = datetime.now()

variables = {
"relationship": {"_id": kwargs.pop("relationship_id")},
"timestamp": int(datetime.now().timestamp() * 1000),
"relationshipId": kwargs.pop("relationship_id"),
"fromEntityId": kwargs.pop("from_entity_id"),
"toEntityId": kwargs.pop("to_entity_id"),
"timestamp": kwargs.pop("timestamp", int(datetime.now().timestamp() * 1000)),
"properties": kwargs.pop("properties", None)
}

properties = kwargs.pop("properties", None)
if properties:
variables["relationship"].update(properties)

response = self._execute_query(query=UPDATE_RELATIONSHIPV2, variables=variables)
return response["data"]["updateRelationshipV2"]
response = self._execute_query(query=UPDATE_RELATIONSHIP, variables=variables)
return response["data"]["updateRelationship"]

def delete_relationship(self, relationship_id: str = None):
"""Deletes a relationship between two entities.
Expand Down
32 changes: 26 additions & 6 deletions jupiterone/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,36 @@
}
}
"""
UPDATE_RELATIONSHIPV2 = """
mutation UpdateRelationshipV2 (
$relationship: JSON!
UPDATE_RELATIONSHIP = """
mutation UpdateRelationship(
$relationshipId: String!
$fromEntityId: String!
$toEntityId: String!
$timestamp: Long
$properties: JSON
) {
updateRelationshipV2 (
relationship: $relationship,
updateRelationship(
relationshipId: $relationshipId,
fromEntityId: $fromEntityId,
toEntityId: $toEntityId,
timestamp: $timestamp,
properties: $properties
) {
relationship
relationship {
_id
_key
_type
_class
_fromEntityId
_toEntityId
displayName
}
edge {
id
fromVertexId
toVertexId
properties
}
}
}
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="jupiterone",
version="1.7.0",
version="2.0.0",
description="A Python client for the JupiterOne API",
license="MIT License",
author="JupiterOne",
Expand Down
Loading
Loading