Exemple #1
0
 def _on_list_files(self, newpacket):
     from main import settings
     if newpacket.Payload != settings.ListFilesFormat():
         return False
     # TODO: perform validations before sending back list of files
     from supplier import list_files
     from crypt import my_keys
     from userid import global_id
     list_files_global_id = global_id.ParseGlobalID(newpacket.PacketID)
     if list_files_global_id['key_id']:
         # customer id and data id can be recognized from packet id
         # return back list of files according to the request
         customer_idurl = list_files_global_id['idurl']
         key_id = list_files_global_id['key_id']
     else:
         # packet id format is unknown
         # by default returning back all files from that recipient if he is a customer
         customer_idurl = newpacket.OwnerID
         key_id = my_keys.make_key_id(alias='customer',
                                      creator_idurl=customer_idurl)
     list_files.send(
         customer_idurl=customer_idurl,
         packet_id=newpacket.PacketID,
         format_type=settings.ListFilesFormat(),
         key_id=key_id,
         remote_idurl=newpacket.OwnerID,  # send back to the requestor
     )
     return True
Exemple #2
0
 def doSendHisFiles(self, *args, **kwargs):
     """
     Action method.
     """
     customer_key_id = my_keys.make_key_id(
         alias='customer', creator_idurl=self.customer_idurl)
     if my_keys.is_key_registered(customer_key_id):
         list_files.send(
             customer_idurl=self.customer_idurl,
             packet_id='%s:%s' % (
                 customer_key_id,
                 packetid.UniqueID(),
             ),
             format_type=settings.ListFilesFormat(),
             key_id=customer_key_id,
             remote_idurl=self.customer_idurl,  # send to the customer
         )
     else:
         # if "customer" key is not delivered to me yet, use his "master" key
         list_files.send(
             customer_idurl=self.customer_idurl,
             packet_id='%s:%s' % (
                 customer_key_id,
                 packetid.UniqueID(),
             ),
             format_type=settings.ListFilesFormat(),
             key_id=my_keys.make_key_id(alias='master',
                                        creator_idurl=self.customer_idurl),
             remote_idurl=self.customer_idurl,  # send to the customer
         )
         lg.err('key %s is not registered, not able to send his files' %
                customer_key_id)
 def _on_list_files(self, newpacket):
     from main import settings
     if newpacket.Payload != settings.ListFilesFormat():
         return False
     # TODO: perform validations before sending back list of files
     from supplier import list_files
     list_files.send(newpacket.OwnerID, newpacket.PacketID,
                     settings.ListFilesFormat())
     return True
Exemple #4
0
 def doSendHisFiles(self, arg):
     """
     Action method.
     """
     packet_id = '%s:%s' % (
         global_id.UrlToGlobalID(self.customer_idurl),
         packetid.UniqueID(),
     )
     list_files.send(self.customer_idurl, packet_id,
                     settings.ListFilesFormat())
 def doSendHisFiles(self, arg):
     """
     Action method.
     """
     customer_key_id = my_keys.make_key_id(alias='customer', creator_idurl=self.customer_idurl)
     if my_keys.is_key_registered(customer_key_id):
         list_files.send(
             customer_idurl=self.customer_idurl,
             packet_id='%s:%s' % (customer_key_id, packetid.UniqueID(), ),
             format_type=settings.ListFilesFormat(),
             key_id=customer_key_id,
             remote_idurl=self.customer_idurl,  # send to the customer
         )
     else:
         lg.warn('key %s is not registered, not able to send his files' % customer_key_id)
Exemple #6
0
def on_list_files(newpacket):
    json_query = {}
    try:
        j = serialization.BytesToDict(newpacket.Payload,
                                      keys_to_text=True,
                                      values_to_text=True)
        j['items'][0]
        json_query = j
    except:
        if strng.to_text(newpacket.Payload) == settings.ListFilesFormat():
            json_query = {
                'items': [
                    '*',
                ],
            }
    if json_query is None:
        lg.exc('unrecognized ListFiles() query received')
        return False
    # TODO: perform validations before sending back list of files
    list_files_global_id = global_id.ParseGlobalID(newpacket.PacketID)
    if list_files_global_id['key_id']:
        # customer id and data id can be recognized from packet id
        # return back list of files according to the request
        customer_idurl = list_files_global_id['idurl']
        key_id = list_files_global_id['key_id']
    else:
        # packet id format is unknown
        # by default returning back all files from that recipient if he is a customer
        customer_idurl = newpacket.OwnerID
        key_id = my_keys.make_key_id(alias='customer',
                                     creator_idurl=customer_idurl)
    key_id = my_keys.latest_key_id(key_id)
    list_files.send(
        customer_idurl=customer_idurl,
        packet_id=newpacket.PacketID,
        format_type=settings.ListFilesFormat(),
        key_id=key_id,
        remote_idurl=newpacket.OwnerID,  # send back to the requesting node
        query_items=json_query['items'],
    )
    return True
Exemple #7
0
def ListFiles(request):
    """
    We will want to use this to see what needs to be resent, and expect normal
    case is very few missing.

    This is to build the ``Files()`` we are holding for a customer.
    """
    if not driver.is_on('service_supplier'):
        return SendFail(request, 'supplier service is off')
    # TODO: use callback module here instead of direct call
    from supplier import list_files
    return list_files.send(request.OwnerID, request.PacketID, request.Payload)