Skip to content

Commit

Permalink
Merge pull request #89 from atsign-foundation/xlin-sessionId-notify
Browse files Browse the repository at this point in the history
fix: added sessionId to notify as default
  • Loading branch information
Xlin123 authored Nov 23, 2023
2 parents ec91bfc + c5f0f1c commit 26ef11e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions at_client/atclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,11 @@ def handle_event(self, queue, at_event):
else:
raise Exception("You must assign a Queue object to the queue paremeter of AtClient class")

def notify(self, at_key : AtKey, value, operation = OperationEnum.UPDATE):
def notify(self, at_key : AtKey, value, operation = OperationEnum.UPDATE, session_id = str(uuid.uuid4())):
iv = at_key.metadata.iv_nonce
shared_key = self.get_encryption_key_shared_by_me(at_key)
encrypted_value = EncryptionUtil.aes_encrypt_from_base64(value, shared_key, iv)
command = NotifyVerbBuilder().with_at_key(at_key, encrypted_value, operation).build()
command = NotifyVerbBuilder().with_at_key(at_key, encrypted_value, operation, session_id).build()
notify_result = self.secondary_connection.execute_command(command)
return notify_result.get_raw_data_response()

Expand Down
10 changes: 8 additions & 2 deletions at_client/util/verbbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ def __init__(self):
self.operation = None
self.message_type = None
self.metadata = None
self.session_id = None

def set_value(self, value):
self.value = value
Expand Down Expand Up @@ -534,8 +535,12 @@ def set_message_type(self, message_type):
def set_namespace(self, namespace):
self.namespace = namespace
return self

def set_session_id(self, session_id):
self.session_id = session_id
return self

def with_at_key(self, at_key, encrypted_value, operation=OperationEnum.UPDATE):
def with_at_key(self, at_key, encrypted_value, operation=OperationEnum.UPDATE, session_id=None):
self.set_key_name(at_key.name)
self.set_shared_by(str(at_key.shared_by))
self.set_shared_with(str(at_key.shared_with))
Expand All @@ -545,6 +550,7 @@ def with_at_key(self, at_key, encrypted_value, operation=OperationEnum.UPDATE):
self.set_metadata(at_key.metadata)
self.set_value(encrypted_value)
self.set_namespace(at_key.namespace)
self.set_session_id(session_id)
self.operation = operation
if self.message_type is None:
self.message_type = MessageTypeEnum.KEY
Expand All @@ -554,7 +560,7 @@ def with_at_key(self, at_key, encrypted_value, operation=OperationEnum.UPDATE):
def build(self):
if self.key is None or (self.shared_with is None and not self.is_public):
raise ValueError("key is None or, you have a public key with no shared_with. These are required fields")
s = f"notify:id:{uuid.uuid4()}:"
s = f"notify:id:{self.session_id}:"
if self.operation:
s+= f"{str(self.operation.value)}"
if self.metadata:
Expand Down

0 comments on commit 26ef11e

Please sign in to comment.