feat(01-01): stage preserved sessions and import typed hashed receipts
This commit is contained in:
1 parent
597caa0b49
commit
cd7783ba3a
3 files changed
+605
No files matched your search
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Local preserved-session and typed evidence CLI (never launches originals).
|
||||
|
||||
Examples: stage --source ../Original --manifest docs/original-manifest.json
|
||||
--output artifacts/fidelity/sessions --session-id fresh-001; identify dist/linux-x64;
|
||||
import BUNDLE/receipt.json --root BUNDLE --output artifacts/fidelity/receipts;
|
||||
validate RECEIPT --root IMPORTED_DIR --allow-open. Synthetic imports require a
|
||||
separate output directory whose name contains 'test'. All outputs remain local.
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
from fidelity_receipts import (identify_tree, identify_report, import_receipt,
|
||||
read_json, stage_original, validate_receipt)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
sub = parser.add_subparsers(dest='command', required=True)
|
||||
stage = sub.add_parser('stage')
|
||||
for flag in ('source', 'manifest', 'output'):
|
||||
stage.add_argument('--' + flag, type=Path, required=True)
|
||||
stage.add_argument('--session-id', required=True)
|
||||
identify = sub.add_parser('identify')
|
||||
identify.add_argument('path', type=Path)
|
||||
for flag in ('report', 'executable', 'resources', 'launcher', 'project'):
|
||||
identify.add_argument('--' + flag, type=Path)
|
||||
imp = sub.add_parser('import')
|
||||
imp.add_argument('receipt', type=Path)
|
||||
imp.add_argument('--root', type=Path, required=True)
|
||||
imp.add_argument('--output', type=Path, required=True)
|
||||
validate = sub.add_parser('validate')
|
||||
validate.add_argument('receipt', type=Path)
|
||||
validate.add_argument('--root', type=Path, required=True)
|
||||
mode = validate.add_mutually_exclusive_group()
|
||||
mode.add_argument('--allow-open', action='store_true')
|
||||
mode.add_argument('--require-complete', action='store_true')
|
||||
args = parser.parse_args(argv)
|
||||
try:
|
||||
if args.command == 'stage':
|
||||
result = stage_original(args.source, args.manifest, args.output, args.session_id)
|
||||
elif args.command == 'identify':
|
||||
result = identify_report(args.path, args.report, args.executable, args.resources,
|
||||
args.launcher, args.project) if any(
|
||||
getattr(args, k) is not None for k in ('report', 'executable', 'resources', 'launcher', 'project')) else identify_tree(args.path)
|
||||
elif args.command == 'import':
|
||||
result = import_receipt(args.receipt, args.root, args.output)
|
||||
else:
|
||||
result = validate_receipt(read_json(args.receipt), args.root)
|
||||
print('Receipt {receipt_id}: {evidence_kind}, status={status}'.format(**result))
|
||||
print('Acceptance: ' + ('ACCEPTED' if result['accepted'] else 'OPEN'))
|
||||
for missing in result['missing_evidence']:
|
||||
print('Missing/open: ' + str(missing))
|
||||
return 1 if args.require_complete and not result['accepted'] else 0
|
||||
print(json.dumps(result, indent=2, allow_nan=False))
|
||||
return 0
|
||||
except (ValueError, OSError, KeyError, TypeError) as error:
|
||||
print('Invalid fidelity evidence: ' + str(error), file=sys.stderr)
|
||||
return 2
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user