Skip to content

Commit

Permalink
Merge pull request #75 from provenant-dev/saidify-schema-script
Browse files Browse the repository at this point in the history
Implemented saidify-schema command to saidify a schema json file
  • Loading branch information
pfeairheller authored Nov 22, 2023
2 parents 3bf34e2 + 59d94a7 commit 54970c7
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <file path of schema file(JSON) to saidify>
```
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
},
)
Expand Down
50 changes: 50 additions & 0 deletions src/vlei/saidify.py
Original file line number Diff line number Diff line change
@@ -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()
133 changes: 133 additions & 0 deletions tests/schema-sample.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
23 changes: 23 additions & 0 deletions tests/test_saidify_schema.py
Original file line number Diff line number Diff line change
@@ -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'


0 comments on commit 54970c7

Please sign in to comment.