##// END OF EJS Templates
Style changes in the tag view page
Style changes in the tag view page

File last commit:

r1586:931a7e94 default
r1617:bbd92ab2 default
Show More
signature.py
158 lines | 4.5 KiB | text/x-python | PythonLexer
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827 import xml.etree.ElementTree as et
neko259
Added signature model. Use signatures in posts
r820 from django.db import models
neko259
Added id-type attribute to attachments to specify a type of hash (currently only md5). Added management command to delete global id caches
r1560 from boards.models import KeyPair
neko259
Added signature model. Use signatures in posts
r820
neko259
Added test for reflinks. Added management command to get posts from other node...
r841 TAG_MODEL = 'model'
TAG_REQUEST = 'request'
TAG_ID = 'id'
TYPE_GET = 'get'
neko259
Rename "pull" request to "list"
r1566 TYPE_LIST = 'list'
neko259
Added test for reflinks. Added management command to get posts from other node...
r841
ATTR_VERSION = 'version'
ATTR_TYPE = 'type'
ATTR_NAME = 'name'
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827 ATTR_KEY = 'key'
ATTR_KEY_TYPE = 'type'
ATTR_LOCAL_ID = 'local-id'
neko259
Added test for reflinks. Added management command to get posts from other node...
r841 class GlobalIdManager(models.Manager):
def generate_request_get(self, global_id_list: list):
"""
Form a get request from a list of ModelId objects.
"""
request = et.Element(TAG_REQUEST)
request.set(ATTR_TYPE, TYPE_GET)
request.set(ATTR_VERSION, '1.0')
model = et.SubElement(request, TAG_MODEL)
model.set(ATTR_VERSION, '1.0')
model.set(ATTR_NAME, 'post')
for global_id in global_id_list:
tag_id = et.SubElement(model, TAG_ID)
global_id.to_xml_element(tag_id)
return et.tostring(request, 'unicode')
neko259
Rename "pull" request to "list"
r1566 def generate_request_list(self):
neko259
Added PULL protocol method implementation without any filters
r1321 """
Form a pull request from a list of ModelId objects.
"""
request = et.Element(TAG_REQUEST)
neko259
Rename "pull" request to "list"
r1566 request.set(ATTR_TYPE, TYPE_LIST)
neko259
Added PULL protocol method implementation without any filters
r1321 request.set(ATTR_VERSION, '1.0')
model = et.SubElement(request, TAG_MODEL)
model.set(ATTR_VERSION, '1.0')
model.set(ATTR_NAME, 'post')
return et.tostring(request, 'unicode')
neko259
Don't allow to import the same post twice
r1232 def global_id_exists(self, global_id):
"""
Checks if the same global id already exists in the system.
"""
return self.filter(key=global_id.key,
key_type=global_id.key_type,
local_id=global_id.local_id).exists()
neko259
Added test for reflinks. Added management command to get posts from other node...
r841
neko259
Added signature model. Use signatures in posts
r820 class GlobalId(models.Model):
neko259
Delete global ID when deleting post. Cache model's content XML tag into global ID
r1520 """
Global model ID and cache.
Key, key type and local ID make a single global identificator of the model.
Content is an XML cache of the model that can be passed along between nodes
without manual serialization each time.
"""
neko259
Added signature model. Use signatures in posts
r820 class Meta:
app_label = 'boards'
neko259
Added test for reflinks. Added management command to get posts from other node...
r841 objects = GlobalIdManager()
neko259
Added signature model. Use signatures in posts
r820 def __init__(self, *args, **kwargs):
models.Model.__init__(self, *args, **kwargs)
if 'key' in kwargs and 'key_type' in kwargs and 'local_id' in kwargs:
self.key = kwargs['key']
self.key_type = kwargs['key_type']
self.local_id = kwargs['local_id']
key = models.TextField()
key_type = models.TextField()
local_id = models.IntegerField()
neko259
Added content field to global id to store cached model content. If a server uses diffrent serialization algorithm, it would still pass the same content string along saving its signature
r1519 content = models.TextField(blank=True, null=True)
neko259
Added signature model. Use signatures in posts
r820
def __str__(self):
neko259
Added test for reflinks. Added management command to get posts from other node...
r841 return '%s::%s::%d' % (self.key_type, self.key, self.local_id)
neko259
Added signature model. Use signatures in posts
r820
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 def to_xml_element(self, element: et.Element):
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827 """
Exports global id to an XML element.
"""
element.set(ATTR_KEY, self.key)
element.set(ATTR_KEY_TYPE, self.key_type)
element.set(ATTR_LOCAL_ID, str(self.local_id))
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 @staticmethod
neko259
Refactored code for getting existing and new global ids
r1233 def from_xml_element(element: et.Element):
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 """
Parses XML id tag and gets global id from it.
Arguments:
element -- the XML 'id' element
neko259
Refactored code for getting existing and new global ids
r1233
Returns:
global_id -- id itself
exists -- True if the global id was taken from database, False if it
did not exist and was created.
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 """
neko259
Refactored code for getting existing and new global ids
r1233 try:
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 return GlobalId.objects.get(key=element.get(ATTR_KEY),
key_type=element.get(ATTR_KEY_TYPE),
local_id=int(element.get(
neko259
Refactored code for getting existing and new global ids
r1233 ATTR_LOCAL_ID))), True
except GlobalId.DoesNotExist:
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 return GlobalId(key=element.get(ATTR_KEY),
key_type=element.get(ATTR_KEY_TYPE),
neko259
Refactored code for getting existing and new global ids
r1233 local_id=int(element.get(ATTR_LOCAL_ID))), False
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836
neko259
Added id-type attribute to attachments to specify a type of hash (currently only md5). Added management command to delete global id caches
r1560 def is_local(self):
"""Checks fo the ID is local model's"""
return KeyPair.objects.filter(
key_type=self.key_type, public_key=self.key).exists()
neko259
Process updated posts from sync server
r1586 def clear_cache(self):
"""
Removes content cache and signatures.
"""
self.content = None
self.save()
self.signature_set.all().delete()
neko259
Added signature model. Use signatures in posts
r820
class Signature(models.Model):
class Meta:
app_label = 'boards'
neko259
Added signatures to the GET response. Added a view to get a full post response for one post. Don't show post key as it is present in the XML post view. Changed key display format
r837 def __init__(self, *args, **kwargs):
models.Model.__init__(self, *args, **kwargs)
if 'key' in kwargs and 'key_type' in kwargs and 'signature' in kwargs:
self.key_type = kwargs['key_type']
self.key = kwargs['key']
self.signature = kwargs['signature']
neko259
Added signature model. Use signatures in posts
r820 key_type = models.TextField()
key = models.TextField()
signature = models.TextField()
neko259
Moved signature set to global id, not post
r1242
global_id = models.ForeignKey('GlobalId')