-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from provenant-dev/saidify-schema-script
Implemented saidify-schema command to saidify a schema json file
- Loading branch information
Showing
5 changed files
with
214 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
|
||
|