From 1eab1b04790b5116c6d9f2b60d3374708d2a9e34 Mon Sep 17 00:00:00 2001 From: Andrea Cimbalo Date: Thu, 9 Mar 2017 19:43:36 +0100 Subject: [PATCH] Resolves #10 using playhouse generic foreign keys --- models/authority.py | 5 ++++- models/certificate.py | 10 ++++------ models/customModel.py | 2 +- models/ssh.py | 4 ++-- models/ssl.py | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/models/authority.py b/models/authority.py index 654d4c9..8b9cc14 100755 --- a/models/authority.py +++ b/models/authority.py @@ -1,12 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from peewee import * +from playhouse.gfk import * import os import os.path from models import customModel +from models.certificate import Certificate from paths import * @@ -16,6 +17,8 @@ Module of base classes to handle authorities class Authority(customModel.CustomModel): + signed_certificates = ReverseGFK(Certificate, 'authority_type', 'authority_id') + request_allowed = [] # data stored in the database diff --git a/models/certificate.py b/models/certificate.py index 7fa2e99..aebbc69 100755 --- a/models/certificate.py +++ b/models/certificate.py @@ -1,14 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from peewee import * +from playhouse.gfk import * import os import json from models import customModel -from models.authority import Authority from paths import * @@ -16,10 +15,9 @@ class Certificate(customModel.CustomModel): """ """ - signed_by = ForeignKeyField( - Authority, - related_name = 'signed_certificates', - ) + authority_type = CharField(null=True) + authority_id = IntegerField(null=True) + authority = GFKField('authority_type', 'authority_id') cert_id = CharField( index = True, diff --git a/models/customModel.py b/models/customModel.py index 74510e1..84a4408 100644 --- a/models/customModel.py +++ b/models/customModel.py @@ -1,5 +1,5 @@ from paths import * -from peewee import * +from playhouse.gfk import * import os custom_db = SqliteDatabase(os.path.join(MANAGER_PATH, 'ca_manager.db')) diff --git a/models/ssh.py b/models/ssh.py index 4611209..e3e64fa 100644 --- a/models/ssh.py +++ b/models/ssh.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from peewee import * +from playhouse.gfk import * from datetime import datetime import os.path @@ -103,7 +103,7 @@ class SSHAuthority(Authority): pub_key_path = request.destination cert = Certificate( - signed_by = self, + authority = self, cert_id = request.req_id, date_issued = datetime.now(), receiver = request.receiver, diff --git a/models/ssl.py b/models/ssl.py index 9e35ab7..cbcb328 100644 --- a/models/ssl.py +++ b/models/ssl.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from peewee import * +from playhouse.gfk import * import os import os.path