def create_certificate_template(config): certificate = create_certificate_section(config) verify = create_verification_section(config) assertion = create_assertion_section(config) recipient = create_recipient_section(config) 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 raw_json = { '@context': 'https://w3id.org/blockcerts/v1', 'type': 'CertificateDocument', 'recipient': recipient, 'assertion': assertion, 'certificate': certificate, 'verify': verify } if config.additional_global_fields: for field in config.additional_global_fields: raw_json = jsonpath_helpers.set_field(raw_json, field['path'], field['value']) if config.additional_per_recipient_fields: for field in config.additional_per_recipient_fields: raw_json = jsonpath_helpers.set_field(raw_json, field['path'], field['value']) template_path = os.path.join(config.abs_data_dir, template_dir, template_file_name) with open(template_path, 'w') as cert_template: json.dump(raw_json, cert_template) return raw_json
def instantiate_recipient(config, cert, recipient): cert['recipient']['givenName'] = recipient.given_name cert['recipient']['familyName'] = recipient.family_name cert['recipient']['publicKey'] = recipient.pubkey if config.hash_emails: salt = helpers.encode(os.urandom(16)) cert['recipient']['salt'] = salt cert['recipient']['identity'] = hash_and_salt_email_address( recipient.identity, salt) else: cert['recipient']['identity'] = recipient.identity 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 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_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