Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the function create_iso8601_tz() in helpers.py #34

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions cert_tools/create_v2_certificate_template.py
Expand Up @@ -147,11 +147,14 @@ def create_certificate_template(config):
return assertion


def get_config():
def get_config(path = None):
cwd = os.getcwd()
config_file_path = os.path.join(cwd, 'conf.ini')
p = configargparse.getArgumentParser(default_config_files=[config_file_path])

if not path:
config_file_path = os.path.join(cwd, 'conf.ini')
else:
config_file_path = path
configargparse.initArgumentParser(name='create_conf', default_config_files=[config_file_path])
p = configargparse.get_argument_parser('create_conf')
p.add('-c', '--my-config', required=False, is_config_file=True, help='config file path')

p.add_argument('--data_dir', type=str, help='where data files are located')
Expand Down
1 change: 1 addition & 0 deletions cert_tools/create_v2_issuer.py
Expand Up @@ -23,6 +23,7 @@ def generate_issuer_file(config):
if config.public_key_created:
issued_on = config.public_key_created
else:
print(helpers.create_iso8601_tz())
issued_on = helpers.create_iso8601_tz()
output_handle = open(config.output_file, 'w') if config.output_file else sys.stdout

Expand Down
7 changes: 3 additions & 4 deletions cert_tools/helpers.py
Expand Up @@ -2,7 +2,7 @@
import json
import os
import sys
from datetime import datetime
from datetime import datetime, timezone

import configargparse
import pytz
Expand Down Expand Up @@ -57,6 +57,5 @@ def encode(num, alphabet=BASE62):


def create_iso8601_tz():
tz = pytz.timezone('UTC')
aware_dt = tz.localize(datetime.now())
return aware_dt.isoformat()
ret = datetime.now(timezone.utc)
return ret.isoformat()
18 changes: 14 additions & 4 deletions cert_tools/instantiate_v2_certificate_batch.py
Expand Up @@ -6,6 +6,7 @@
'''
import copy
import csv
import sys
import hashlib
import json
import os
Expand Down Expand Up @@ -74,6 +75,7 @@ def instantiate_recipient(config, cert, recipient):


def create_unsigned_certificates_from_roster(config):
csv.field_size_limit(sys.maxsize)
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()
Expand All @@ -82,16 +84,18 @@ def create_unsigned_certificates_from_roster(config):

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

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

cur = 0
for recipient in recipients:
cur = cur + 1
print('Proceeding ' + str(cur) + ' of ' + str(len(recipients)) + ' ...')
if config.filename_format == "certname_identity":
uid = template['badge']['name'] + recipient.identity
uid = "".join(c for c in uid if c.isalnum())
Expand All @@ -113,9 +117,15 @@ def create_unsigned_certificates_from_roster(config):
json.dump(cert, unsigned_cert)


def get_config():
def get_config(path = None):
cwd = os.getcwd()
p = configargparse.getArgumentParser(default_config_files=[os.path.join(cwd, 'conf.ini')])
if not path:
config_file_path = os.path.join(cwd, 'conf.ini')
else:
config_file_path = path
configargparse.initArgumentParser(name='inst_conf', default_config_files=[config_file_path])
p = configargparse.get_argument_parser('inst_conf')

p.add('-c', '--my-config', required=False, is_config_file=True, help='config file path')
p.add_argument('--data_dir', type=str, help='where data files are located')
p.add_argument('--issuer_certs_url', type=str, help='issuer certificates URL')
Expand Down
28 changes: 14 additions & 14 deletions conf.ini
@@ -1,17 +1,17 @@
# issuer information
issuer_url = https://www.issuer.org
issuer_email = contact@issuer.org
issuer_name = University of Learning
issuer_id = https://www.blockcerts.org/samples/2.0/issuer-testnet.json
revocation_list=https://www.blockcerts.org/samples/2.0/revocation-list-testnet.json
issuer_url = https://www.ust.hk/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you exclude this file from the PR? conf.ini should be in .gitignore (sorry about that!); so if you wanted to make that change too, that would avoid this happening in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Kim,

I just found that I wrongly submitted another commit which is on Jan 12. I will try withdraw that, I intended to just submit the one in Dec.

Thanks for your work!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will create another pull request =)

issuer_email = blockcert@hkust.org
issuer_name = Hong Kong University of Science and Technology
issuer_id = https://raw.githubusercontent.com/ppfish45/Blockcerts_test/master/test.json
revocation_list = https://raw.githubusercontent.com/ppfish45/Blockcerts_test/master/revocation_list.json
issuer_signature_lines={"fields": [{"job_title": "University Issuer","signature_image": "images/issuer-signature.png","name": "Your signature"}]}
issuer_public_key=ecdsa-koblitz-pubkey:msBCHdwaQ7N2ypBYupkp6uNxtr9Pg76imj
issuer_public_key = ecdsa-koblitz-pubkey:15uhtvSU99qqk8rp6BRUX2XgLS9Km7qow9

# certificate information
certificate_description = Lorem ipsum dolor sit amet, mei docendi concludaturque ad, cu nec partem graece. Est aperiam consetetur cu, expetenda moderatius neglegentur ei nam, suas dolor laudem eam an.
certificate_title = Certificate of Accomplishment
criteria_narrative=Nibh iriure ei nam, modo ridens neglegentur mel eu. At his cibo mucius.
badge_id = 82a4c9f2-3588-457b-80ea-da695571b8fc
certificate_description = The First Blockcert of HKUST
certificate_title = Graduate Diploma
criteria_narrative = BSc in Sixology
badge_id = 92260118-7360-4bb3-af88-e119aee03072

# images
issuer_logo_file = images/logo.png
Expand All @@ -22,16 +22,16 @@ issuer_signature_file = images/issuer-signature.png
## TEMPLATE DATA ##
###################

data_dir = sample_data
data_dir = demo_dir
# template output directory
template_dir = certificate_templates
template_file_name = test.json
template_file_name = template.json

##############################
## INSTANTIATE BATCH CONFIG ##
##############################
unsigned_certificates_dir = unsigned_certificates
roster = rosters/roster_testnet.csv
roster = rosters/roster.csv
filename_format = uuid
no_clobber = True

Expand All @@ -46,7 +46,7 @@ no_clobber = True
# - the jsonpath to the field
# - the global value to use
# additional_global_fields = {"fields": [{"path": "$.certificate.subtitle","value": "kim custom subtitle"}]}
additional_global_fields = {"fields": [{"path": "$.displayHtml","value": "<h1>Some html code</h1>"}, {"path": "$.@context","value": ["https://w3id.org/openbadges/v2", "https://w3id.org/blockcerts/v2", {"displayHtml": { "@id": "schema:description" }}]}]}
additional_global_fields = {"fields": [{"path": "$.displayHtml","value": "some html codes"}, {"path": "$.@context","value": ["https://w3id.org/openbadges/v2", "https://w3id.org/blockcerts/v2", {"displayHtml": { "@id": "schema:description" }},{"degree": { "@id": "schema:description" }}, {"level": { "@id": "schema:description" }}]}]}

# can specify an array of additional per-recipient fields. For each additional field, you must indicate:
# - the jsonpath to the field
Expand Down
1 change: 0 additions & 1 deletion sample_data/certificate_templates/test.json

This file was deleted.

Binary file removed sample_data/images/certificate-image.png
Binary file not shown.
Binary file removed sample_data/images/issuer-signature.png
Binary file not shown.
Binary file removed sample_data/images/logo.png
Binary file not shown.
3 changes: 0 additions & 3 deletions sample_data/rosters/roster_mainnet.csv

This file was deleted.

3 changes: 0 additions & 3 deletions sample_data/rosters/roster_testnet.csv

This file was deleted.

This file was deleted.

This file was deleted.