def create_unsigned_certificates_from_roster(config):
    roster = os.path.join(config.abs_data_dir, config.roster)
    template = os.path.join(config.abs_data_dir, config.template_dir,
                            config.template_file_name)
    issued_on = helpers.create_iso8601_tz()
    output_dir = os.path.join(config.abs_data_dir,
                              config.unsigned_certificates_dir)
    print('Writing certificates to ' + output_dir)

    recipients = []
    with open(roster, 'r') as theFile:
        reader = csv.DictReader(theFile)
        for line in reader:
            r = Recipient(line)
            recipients.append(r)

    with open(template) as template:
        cert_str = template.read()
        template = json.loads(cert_str)

        for recipient in recipients:
            uid = str(uuid.uuid4())

            cert = copy.deepcopy(template)

            instantiate_assertion(config, cert, uid, issued_on)
            instantiate_recipient(config, cert, recipient)

            # validate certificate before writing
            schema_validator.validate_v2(cert)

            with open(os.path.join(output_dir, uid + '.json'),
                      'w') as unsigned_cert:
                json.dump(cert, unsigned_cert)
def create_unsigned_certificates_from_roster(template, recipients, use_identities, additionalFields, hash_emails):
    issued_on = helpers.create_iso8601_tz()

    certs = {}
    for recipient in recipients:
        if use_identities:
            uid = template['badge']['name'] + recipient.identity
            uid = "".join(c for c in uid if c.isalnum())
        else:
            uid = str(uuid.uuid4())

        cert = copy.deepcopy(template)

        instantiate_assertion(cert, uid, issued_on)
        instantiate_recipient(cert, recipient, additionalFields, hash_emails)

        # validate certificate before writing
        schema_validator.validate_v2(cert)

        certs[uid] = cert
    return certs
Ejemplo n.º 3
0
def create_unsigned_certificates_from_roster(config):
    roster = os.path.join(config.abs_data_dir, config.roster)
    template = os.path.join(config.abs_data_dir, config.template_dir,
                            config.template_file_name)
    issued_on = helpers.create_iso8601_tz()
    output_dir = os.path.join(config.abs_data_dir,
                              config.unsigned_certificates_dir)
    print('Writing certificates to ' + output_dir)

    recipients = []
    with open(roster, 'r') as theFile:
        reader = csv.DictReader(theFile)
        for line in reader:
            r = Recipient(line)
            recipients.append(r)

    with open(template) as template:
        cert_str = template.read()
        template = json.loads(cert_str)

        for recipient in recipients:
            if config.filename_format == "certname_identity":
                uid = template['badge']['name'] + recipient.identity
                uid = "".join(c for c in uid if c.isalnum())
            else:
                uid = str(uuid.uuid4())
            cert_file = os.path.join(output_dir, uid + '.json')
            if os.path.isfile(cert_file) and config.no_clobber:
                continue

            cert = copy.deepcopy(template)

            instantiate_assertion(config, cert, uid, issued_on)
            instantiate_recipient(config, cert, recipient)

            # validate certificate before writing
            schema_validator.validate_v2(cert)

            with open(cert_file, 'w') as unsigned_cert:
                json.dump(cert, unsigned_cert)
def create_unsigned_certificates_from_roster(config):
    roster = os.path.join(config.abs_data_dir, config.roster)
    template = os.path.join(config.abs_data_dir, config.template_dir, config.template_file_name)
    issued_on = helpers.create_iso8601_tz()
    output_dir = os.path.join(config.abs_data_dir, config.unsigned_certificates_dir)
    print('Writing certificates to ' + output_dir)

    recipients = []
    with open(roster, 'r') as theFile:
        reader = csv.DictReader(theFile)
        for line in reader:
            r = Recipient(line)
            recipients.append(r)

    with open(template) as template:
        cert_str = template.read()
        template = json.loads(cert_str)

        for recipient in recipients:
            if config.filename_format == "certname_identity":
                uid = template['badge']['name'] + recipient.identity
                uid = "".join(c for c in uid if c.isalnum())
            else:
                uid = str(uuid.uuid4())
            cert_file = os.path.join(output_dir, uid + '.json')
            if os.path.isfile(cert_file) and config.no_clobber:
                continue

            cert = copy.deepcopy(template)

            instantiate_assertion(config, cert, uid, issued_on)
            instantiate_recipient(config, cert, recipient)

            # validate certificate before writing
            schema_validator.validate_v2(cert)

            with open(cert_file, 'w') as unsigned_cert:
                json.dump(cert, unsigned_cert)
Ejemplo n.º 5
0
def create_unsigned_certificates_from_roster(template, recipients,
                                             use_identities, additionalFields,
                                             hash_emails):
    issued_on = helpers.create_iso8601_tz()

    certs = {}
    for recipient in recipients:
        if use_identities:
            uid = template['badge']['name'] + recipient.identity
            uid = "".join(c for c in uid if c.isalnum())
        else:
            uid = str(uuid.uuid4())

        cert = copy.deepcopy(template)

        instantiate_assertion(cert, uid, issued_on)
        instantiate_recipient(cert, recipient, additionalFields, hash_emails)

        # validate certificate before writing
        schema_validator.validate_v2(cert)

        certs[uid] = cert
    return certs
def create_unsigned_certificates_from_roster(config):
    roster = os.path.join(config.abs_data_dir, config.roster)
    template = os.path.join(config.abs_data_dir, config.template_dir,
                            config.template_file_name)
    issued_on = helpers.create_iso8601_tz()
    output_dir = os.path.join(config.abs_data_dir,
                              config.unsigned_certificates_dir)
    print('Writing certificates to ' + output_dir)

    recipients = []

    ### User defined changes. Defined a mapping list for keeping user mapping. ###
    mapping = []
    ### END ###

    with open(roster, 'r') as theFile:
        reader = csv.DictReader(theFile)
        for line in reader:
            r = Recipient(line)
            recipients.append(r)

    with open(template) as template:
        cert_str = template.read()
        template = json.loads(cert_str)

        for recipient in recipients:
            if config.filename_format == "certname_identity":
                uid = template['badge']['name'] + recipient.identity
                uid = "".join(c for c in uid if c.isalnum())
            else:
                uid = str(uuid.uuid4())

            ### User-defined changes. Added a field to change the certificate Image for a given recipient ###
            template['badge']['image'] = helpers.encode_image(
                os.path.join(config.abs_data_dir,
                             'images/' + recipient.imagefile))
            ### END ###

            cert_file = os.path.join(output_dir, uid + '.json')
            if os.path.isfile(cert_file) and config.no_clobber:
                continue

            cert = copy.deepcopy(template)

            instantiate_assertion(config, cert, uid, issued_on)
            instantiate_recipient(config, cert, recipient)

            # validate certificate before writing
            schema_validator.validate_v2(cert)

            with open(cert_file, 'w') as unsigned_cert:
                json.dump(cert, unsigned_cert)

            ###UserDefined changes. Creating a mapping for recepient email and filename
            mapping.append([recipient.identity, uid + '.json'])
            ### END ###

        ### User Defined changes. Writes to the mapping csv file ###
        with open(os.path.join(config.abs_data_dir, 'mapping.csv'),
                  'w') as mappingFile:
            writer = csv.writer(mappingFile)
            writer.writerows(mapping)