iterate over subject details

This commit is contained in:
sayali 2020-10-20 17:17:28 -07:00
parent 788703ce12
commit 01dddd2a55
1 changed files with 8 additions and 10 deletions

View File

@ -340,6 +340,8 @@ class CertificateOutputSchema(LemurOutputSchema):
@post_dump @post_dump
def handle_subject_details(self, data): def handle_subject_details(self, data):
subject_details = ["country", "state", "location", "organization", "organizational_unit"]
# Remove subject details if authority is CA/Browser Forum compliant. The code will use default set of values in that case. # Remove subject details if authority is CA/Browser Forum compliant. The code will use default set of values in that case.
# If CA/Browser Forum compliance of an authority is unknown (None), it is safe to fallback to default values. Thus below # If CA/Browser Forum compliance of an authority is unknown (None), it is safe to fallback to default values. Thus below
# condition checks for 'not False' ==> 'True or None' # condition checks for 'not False' ==> 'True or None'
@ -347,17 +349,13 @@ class CertificateOutputSchema(LemurOutputSchema):
is_cab_compliant = data.get("authority").get("isCabCompliant") is_cab_compliant = data.get("authority").get("isCabCompliant")
if is_cab_compliant is not False: if is_cab_compliant is not False:
data.pop("country", None) for field in subject_details:
data.pop("state", None) data.pop(field, None)
data.pop("location", None)
data.pop("organization", None)
data.pop("organizational_unit", None)
# Removing optional fields if None, else it complains in de-serialization # Removing subject fields if None, else it complains in de-serialization
if "location" in data and data["location"] is None: for field in subject_details:
data.pop("location") if field in data and data[field] is None:
if "organizational_unit" in data and data["organizational_unit"] is None: data.pop(field)
data.pop("organizational_unit")
class CertificateShortOutputSchema(LemurOutputSchema): class CertificateShortOutputSchema(LemurOutputSchema):