From 86d80521c092a51e584c71c187cd0be3d62407df Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sun, 29 Jul 2018 17:03:51 +0200 Subject: [PATCH] Exposition des sshfpr via api rest --- api/serializers.py | 18 +++++++++++++++++- machines/models.py | 4 +++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/api/serializers.py b/api/serializers.py index bff1bd9c..51afd468 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -716,6 +716,21 @@ class CNAMERecordSerializer(serializers.ModelSerializer): fields = ('alias', 'hostname', 'extension') +class SSHFPRRecordSerializer(serializers.ModelSerializer): + class Meta: + model = machines.SshFingerprint + fields = ('algo_id', 'hash') + + +class SSHFPRInterfaceSerializer(serializers.ModelSerializer): + hostname = serializers.CharField(source='domain.name', read_only=True) + sshfpr = SSHFPRRecordSerializer(source='machine.sshfingerprint_set', many=True, read_only=True) + + class Meta: + model = machines.Interface + fields = ('hostname', 'sshfpr') + + class DNSZonesSerializer(serializers.ModelSerializer): """Serialize the data about DNS Zones. """ @@ -729,12 +744,13 @@ class DNSZonesSerializer(serializers.ModelSerializer): a_records = ARecordSerializer(many=True, source='get_associated_a_records') aaaa_records = AAAARecordSerializer(many=True, source='get_associated_aaaa_records') cname_records = CNAMERecordSerializer(many=True, source='get_associated_cname_records') + sshfpr_records = SSHFPRInterfaceSerializer(many=True, source='get_associated_sshfpr') class Meta: model = machines.Extension fields = ('name', 'soa', 'ns_records', 'originv4', 'originv6', 'mx_records', 'txt_records', 'srv_records', 'a_records', - 'aaaa_records', 'cname_records') + 'aaaa_records', 'cname_records', 'sshfpr_records') # MAILING diff --git a/machines/models.py b/machines/models.py index 5dd75fb2..ca8e8c1b 100644 --- a/machines/models.py +++ b/machines/models.py @@ -636,7 +636,9 @@ class Extension(RevMixin, AclMixin, models.Model): from re2o.utils import all_active_assigned_interfaces return (all_active_assigned_interfaces() .filter(type__ip_type__extension=self) - .filter(machine)) + .filter( + machine__id__in=SshFingerprint.objects.values('machine') + )) def get_associated_a_records(self): from re2o.utils import all_active_assigned_interfaces