def instantiate_recipient(config, cert, recipient): if config.hash_emails: salt = helpers.encode(os.urandom(16)) cert['recipient']['hashed'] = True cert['recipient']['salt'] = salt cert['recipient']['identity'] = hash_and_salt_email_address( recipient.identity, salt) else: cert['recipient']['identity'] = recipient.identity cert['recipient']['hashed'] = False profile_field = scope_name('recipientProfile') cert[profile_field] = {} cert[profile_field]['type'] = ['RecipientProfile', 'Extension'] cert[profile_field]['name'] = recipient.name cert[profile_field][ 'publicKey'] = 'ecdsa-koblitz-pubkey:' + recipient.pubkey if config.additional_per_recipient_fields: if not recipient.additional_fields: raise Exception( 'expected additional recipient fields in the csv file but none found' ) for field in config.additional_per_recipient_fields: cert = jsonpath_helpers.set_field( cert, field['path'], recipient.additional_fields[field['csv_column']]) else: if recipient.additional_fields: # throw an exception on this in case it's a user error. We may decide to remove this if it's a nuisance raise Exception( 'there are fields in the csv file that are not expected by the additional_per_recipient_fields configuration' )
def create_badge_section(config): cert_image_path = os.path.join(config.abs_data_dir, config.cert_image_file) issuer_image_path = os.path.join(config.abs_data_dir, config.issuer_logo_file) with open('data.json') as data_file: award_obj = json.load(data_file) badge = { 'type': 'BadgeClass', 'id': helpers.URN_UUID_PREFIX + config.badge_id, 'name': award_obj['Award']['Title'], 'description': award_obj['Award']['Description'], 'image': helpers.encode_image(cert_image_path), 'issuer': { 'id': config.issuer_id, 'type': 'Profile', 'name': award_obj['Award']['IssuerName'], 'url': award_obj['Award']['IssuerUrl'], 'email': award_obj['Award']['IssuerContact'], 'image': helpers.encode_image(issuer_image_path), 'revocationList': config.revocation_list } } badge['criteria'] = {} badge['criteria']['narrative'] = award_obj['Criteria'] if config.issuer_signature_lines: signature_lines = [] for signature_line in config.issuer_signature_lines: signature_image_path = os.path.join( config.abs_data_dir, signature_line['signature_image']) signature_lines.append({ 'type': ['SignatureLine', 'Extension'], 'jobTitle': signature_line['job_title'], 'image': helpers.encode_image(signature_image_path), 'name': signature_line['name'] }) badge[scope_name('signatureLines')] = signature_lines return badge
def create_certificate_template(config): if not config.badge_id: badge_uuid = str(uuid.uuid4()) print('Generated badge id {0}'.format(badge_uuid)) config.badge_id = badge_uuid badge = create_badge_section(config) verification = create_verification_section(config) assertion = create_assertion_section(config) recipient = create_recipient_section(config) recipient_profile = create_recipient_profile_section() template_dir = config.template_dir if not os.path.isabs(template_dir): template_dir = os.path.join(config.abs_data_dir, template_dir) template_file_name = config.template_file_name assertion['recipient'] = recipient assertion[scope_name('recipientProfile')] = recipient_profile assertion['badge'] = badge assertion['verification'] = verification if config.additional_global_fields: for field in config.additional_global_fields: assertion = jsonpath_helpers.set_field(assertion, field['path'], field['value']) if config.additional_per_recipient_fields: for field in config.additional_per_recipient_fields: assertion = jsonpath_helpers.set_field(assertion, field['path'], field['value']) template_path = os.path.join(config.abs_data_dir, template_dir, template_file_name) print('Writing template to ' + template_path) with open(template_path, 'w') as cert_template: json.dump(assertion, cert_template) return assertion
def create_badge_section(config): cert_image_path = os.path.join(config.abs_data_dir, config.cert_image_file) issuer_image_path = os.path.join(config.abs_data_dir, config.issuer_logo_file) badge = { 'type': 'BadgeClass', 'id': helpers.URN_UUID_PREFIX + config.badge_id, 'name': config.certificate_title, 'description': config.certificate_description, 'image': helpers.encode_image(cert_image_path), 'issuer': { 'id': config.issuer_id, 'type': 'Profile', 'name': config.issuer_name, 'url': config.issuer_url, 'email': config.issuer_email, 'image': helpers.encode_image(issuer_image_path), 'revocationList': config.revocation_list } } badge['criteria'] = {} badge['criteria']['narrative'] = config.criteria_narrative if config.issuer_signature_lines: signature_lines = [] signature_lines = [] for signature_line in config.issuer_signature_lines: signature_image_path = os.path.join( config.abs_data_dir, signature_line['signature_image']) signature_lines.append({ 'type': ['SignatureLine', 'Extension'], 'jobTitle': signature_line['job_title'], 'image': helpers.encode_image(signature_image_path), 'name': signature_line['name'] }) badge[scope_name('signatureLines')] = signature_lines return badge