-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc1ef77
commit 306b26a
Showing
9 changed files
with
576 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
from indykite_sdk.indykite.identity.v1beta2 import identity_management_api_pb2 as pb2 | ||
import sys | ||
from indykite_sdk.utils.logger import handle_excepthook, logger_error | ||
from google.protobuf.timestamp_pb2 import Timestamp | ||
from indykite_sdk.indykite.objects.v1beta1 import struct_pb2 as struct | ||
from indykite_sdk.utils.message_to_value import arg_to_value | ||
from indykite_sdk.model.invitation import Invitation | ||
|
||
|
||
def create_email_invitation(self, tenant_id, reference_id, email, invite_at_time, expire_time, message_attributes): | ||
sys.excepthook = handle_excepthook | ||
try: | ||
invite_at_time_seconds = None | ||
if invite_at_time: | ||
invite_at_time_seconds = Timestamp(seconds=invite_at_time) | ||
expire_time_seconds = None | ||
if expire_time: | ||
expire_time_seconds = Timestamp(seconds=expire_time) | ||
fields = {} | ||
if message_attributes: | ||
for key, value in message_attributes.items(): | ||
fields[key] = arg_to_value(value) | ||
|
||
request = pb2.CreateInvitationRequest( | ||
tenant_id=str(tenant_id), | ||
reference_id=str(reference_id), | ||
email=str(email), | ||
message_attributes=struct.MapValue(fields=fields), | ||
invite_at_time=invite_at_time_seconds, | ||
expire_time=expire_time_seconds | ||
) | ||
response = self.stub.CreateInvitation(request) | ||
if not response: | ||
return None | ||
return response | ||
|
||
except Exception as exception: | ||
return logger_error(exception) | ||
|
||
|
||
def create_mobile_invitation(self, tenant_id, reference_id, mobile, invite_at_time, expire_time, message_attributes): | ||
# mobile not implemented yet | ||
sys.excepthook = handle_excepthook | ||
try: | ||
invite_at_time_seconds = None | ||
if invite_at_time: | ||
invite_at_time_seconds = Timestamp(seconds=invite_at_time) | ||
expire_time_seconds = None | ||
if expire_time: | ||
expire_time_seconds = Timestamp(seconds=expire_time) | ||
fields = {} | ||
if message_attributes: | ||
for key, value in message_attributes.items(): | ||
fields[key] = arg_to_value(value) | ||
|
||
request = pb2.CreateInvitationRequest( | ||
tenant_id=str(tenant_id), | ||
reference_id=str(reference_id), | ||
mobile=str(mobile), | ||
message_attributes=struct.MapValue(fields=fields), | ||
invite_at_time=invite_at_time_seconds, | ||
expire_time=expire_time_seconds | ||
) | ||
response = self.stub.CreateInvitation(request) | ||
if not response: | ||
return None | ||
return response | ||
|
||
except Exception as exception: | ||
return logger_error(exception) | ||
|
||
|
||
def check_invitation_state(self, reference_id, invitation_token): | ||
sys.excepthook = handle_excepthook | ||
try: | ||
if reference_id and invitation_token: | ||
return logger_error("You can not specify both the reference ID and the invitation token") | ||
elif not reference_id and not invitation_token: | ||
return logger_error("You have not specified any identifier: neither reference ID nor invitation token") | ||
response = self.stub.CheckInvitationState( | ||
pb2.CheckInvitationStateRequest( | ||
reference_id=reference_id, | ||
invitation_token=invitation_token | ||
) | ||
) | ||
return Invitation.deserialize(response.invitation) | ||
except Exception as exception: | ||
return logger_error(exception) | ||
|
||
|
||
def resend_invitation(self, reference_id): | ||
sys.excepthook = handle_excepthook | ||
try: | ||
response = self.stub.ResendInvitation( | ||
pb2.ResendInvitationRequest( | ||
reference_id=reference_id | ||
) | ||
) | ||
return response | ||
except Exception as exception: | ||
return logger_error(exception) | ||
|
||
|
||
def cancel_invitation(self, reference_id): | ||
sys.excepthook = handle_excepthook | ||
try: | ||
response = self.stub.CancelInvitation( | ||
pb2.CancelInvitationRequest( | ||
reference_id=reference_id | ||
) | ||
) | ||
return response | ||
except Exception as exception: | ||
return logger_error(exception) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from indykite_sdk.indykite.identity.v1beta2.model_pb2 import Invitation, DigitalTwin | ||
from indykite_sdk.utils import timestamp_to_date | ||
from google.protobuf.json_format import MessageToDict | ||
|
||
|
||
class Invitation: | ||
@classmethod | ||
def deserialize(cls, message): | ||
if message is None: | ||
return None | ||
invitation = Invitation( | ||
tenant_id=str(message.tenant_id), | ||
reference_id = str(message.reference_id), | ||
state = message.state) | ||
if message.HasField('invite_at_time'): | ||
invitation.invite_at_time = timestamp_to_date(message.invite_at_time) | ||
if message.HasField('expire_time'): | ||
invitation.expire_time = timestamp_to_date(message.expire_time) | ||
if message.HasField('message_attributes'): | ||
invitation.message_attributes = MessageToDict(message.message_attributes) | ||
if message.HasField('accepted_by'): | ||
invitation.accepted_by = DigitalTwin(id=message.accepted_by.id, | ||
tenant_id=message.accepted_by.tenant_id, | ||
kind=message.accepted_by.kind, | ||
state=message.accepted_by.state, | ||
tags=message.accepted_by.tags) | ||
|
||
if message.HasField('email'): | ||
invitation.email = str(message.email) | ||
if message.HasField('mobile'): | ||
invitation.mobile = str(message.mobile) | ||
|
||
return invitation | ||
|
||
def __init__(self, tenant_id, reference_id, state): | ||
|
||
self.tenant_id = tenant_id | ||
self.reference_id = reference_id | ||
self.state = state | ||
self.invite_at_time = None | ||
self.expire_time = None | ||
self.message_attributes = None | ||
self.accepted_by = None | ||
self.email = None | ||
self.mobile = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.