diff --git a/README.md b/README.md index bc54e37..faace6b 100644 --- a/README.md +++ b/README.md @@ -39,3 +39,9 @@ To generate new SAIDs for updates schema run: ```shell python3 src/vlei/generate.py ``` + +To Saidify a schema json file and add the schema to ./schema/acdc folder, run: + +```shell +saidify-schema -f +``` diff --git a/setup.py b/setup.py index 9ab1a55..11f3bcf 100644 --- a/setup.py +++ b/setup.py @@ -94,7 +94,8 @@ entry_points={ 'console_scripts': [ 'vLEI-generate = vlei.generate:main', - 'vLEI-server = vlei.server:main' + 'vLEI-server = vlei.server:main', + 'saidify-schema = vlei.saidify:main' ] }, ) diff --git a/src/vlei/saidify.py b/src/vlei/saidify.py new file mode 100644 index 0000000..e6bf814 --- /dev/null +++ b/src/vlei/saidify.py @@ -0,0 +1,50 @@ +# -*- encoding: utf-8 -*- +""" +SaidifySchema module + +""" +import argparse +import json +import os +import falcon +from hio.base import doing +from hio.core import http +from keri.core import coring, scheming + +from vlei.app import generating + +parser = argparse.ArgumentParser(description="Saidify schema json file and add to schema directory") +parser.add_argument('--file', '-f', + default="", + required=True, + help='file path of schema file(JSON) to saidify') +parser.add_argument('-s', '--schema-dir', + action='store', dest="schemaDir", + default="schema/acdc", + help="Directory of schemas to store schema file") + + +def saidify(args): + ff = open(args.file, 'r') + jsn = json.load(ff) + ff.close() + sad = generating.populateSAIDS(jsn) + schemer = scheming.Schemer(sed=sad) + + s = open(args.file, 'w') + s.write(json.dumps(schemer.sed, indent=2)) + + rootDir = os.path.abspath(os.curdir) + fileName = os.path.basename(args.file) + f = open(os.path.join(rootDir, args.schemaDir ,fileName), "w") + f.write(json.dumps(schemer.sed, indent=2)) + f.close() + + +def main(): + args = parser.parse_args() + saidify(args) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/tests/schema-sample.json b/tests/schema-sample.json new file mode 100644 index 0000000..1f4b231 --- /dev/null +++ b/tests/schema-sample.json @@ -0,0 +1,133 @@ +{ + "$id": "EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao", + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Qualified vLEI Issuer Credential", + "description": "A vLEI Credential issued by GLEIF to Qualified vLEI Issuers which allows the Qualified vLEI Issuers to issue, verify and revoke Legal Entity vLEI Credentials and Legal Entity Official Organizational Role vLEI Credentials", + "type": "object", + "credentialType": "QualifiedvLEIIssuervLEICredential", + "version": "1.0.0", + "properties": { + "v": { + "description": "Version", + "type": "string" + }, + "d": { + "description": "Credential SAID", + "type": "string" + }, + "u": { + "description": "One time use nonce", + "type": "string" + }, + "i": { + "description": "GLEIF Issuee AID", + "type": "string" + }, + "ri": { + "description": "Credential status registry", + "type": "string" + }, + "s": { + "description": "Schema SAID", + "type": "string" + }, + "a": { + "oneOf": [ + { + "description": "Attributes block SAID", + "type": "string" + }, + { + "$id": "ELGgI0fkloqKWREXgqUfgS0bJybP1LChxCO3sqPSFHCj", + "description": "Attributes block", + "type": "object", + "properties": { + "d": { + "description": "Attributes block SAID", + "type": "string" + }, + "i": { + "description": "QVI Issuee AID", + "type": "string" + }, + "dt": { + "description": "Issuance date time", + "type": "string", + "format": "date-time" + }, + "LEI": { + "description": "LEI of the requesting Legal Entity", + "type": "string", + "format": "ISO 17442" + }, + "gracePeriod": { + "description": "Allocated grace period", + "type": "integer", + "default": 90 + } + }, + "additionalProperties": false, + "required": [ + "i", + "dt", + "LEI" + ] + } + ] + }, + "r": { + "oneOf": [ + { + "description": "Rules block SAID", + "type": "string" + }, + { + "$id": "ECllqarpkZrSIWCb97XlMpEZZH3q4kc--FQ9mbkFMb_5", + "description": "Rules block", + "type": "object", + "properties": { + "d": { + "description": "Rules block SAID", + "type": "string" + }, + "usageDisclaimer": { + "description": "Usage Disclaimer", + "type": "object", + "properties": { + "l": { + "description": "Associated legal language", + "type": "string", + "const": "Usage of a valid, unexpired, and non-revoked vLEI Credential, as defined in the associated Ecosystem Governance Framework, does not assert that the Legal Entity is trustworthy, honest, reputable in its business dealings, safe to do business with, or compliant with any laws or that an implied or expressly intended purpose will be fulfilled." + } + } + }, + "issuanceDisclaimer": { + "description": "Issuance Disclaimer", + "type": "object", + "properties": { + "l": { + "description": "Associated legal language", + "type": "string", + "const": "All information in a valid, unexpired, and non-revoked vLEI Credential, as defined in the associated Ecosystem Governance Framework, is accurate as of the date the validation process was complete. The vLEI Credential has been issued to the legal entity or person named in the vLEI Credential as the subject; and the qualified vLEI Issuer exercised reasonable care to perform the validation process set forth in the vLEI Ecosystem Governance Framework." + } + } + } + }, + "additionalProperties": false, + "required": [ + "d", + "usageDisclaimer", + "issuanceDisclaimer" + ] + } + ] + } + }, + "additionalProperties": false, + "required": [ + "i", + "ri", + "s", + "d" + ] +} \ No newline at end of file diff --git a/tests/test_saidify_schema.py b/tests/test_saidify_schema.py new file mode 100644 index 0000000..2d5c193 --- /dev/null +++ b/tests/test_saidify_schema.py @@ -0,0 +1,23 @@ +import json +from pathlib import Path + +import os + +import multicommand +import pytest +from keri.core import scheming +import subprocess + +TEST_DIR = os.path.dirname(os.path.abspath(__file__)) + +def test_saidify_schema_command(): + + filepath = os.path.join(TEST_DIR, "schema-sample.json") + result = subprocess.run(['saidify-schema', '--file', filepath, '--schema-dir', TEST_DIR], capture_output=True) + + with open(filepath) as f: + sed = json.load(f) + schemer = scheming.Schemer(sed=sed) + assert schemer.said == 'EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao' + + \ No newline at end of file