package-enterprise-auth.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """Build a nonsecret target-side authorization support package, without altering r2."""
  2. import hashlib
  3. import io
  4. import json
  5. from pathlib import Path
  6. import subprocess
  7. import sys
  8. import zipfile
  9. sys.dont_write_bytecode = True
  10. ROOT = Path(__file__).resolve().parents[1]
  11. OUT = ROOT / 'docs/ksf-enterprise-auth-support-20261110-r1'
  12. NAME = OUT.name
  13. sha = lambda b: hashlib.sha256(b).hexdigest()
  14. encode = lambda v: (json.dumps(v, ensure_ascii=False, indent=2) + '\n').encode()
  15. def main():
  16. if OUT.exists():
  17. raise ValueError('NEW_RELEASE_DIRECTORY_REQUIRED')
  18. validation = json.loads((ROOT / 'work/enterprise-workshop-20261110/validation-auth-r1.json').read_bytes())
  19. assert validation['ok'] and validation['testsRun'] == 50
  20. names = ['common.mjs', 'export-recipient.mjs', 'install.mjs', 'decrypt-envelope.mjs', 'README.md']
  21. files = {n: (ROOT / 'scripts/enterprise-auth' / n).read_bytes() for n in names}
  22. for n in names:
  23. if n.endswith('.mjs'):
  24. result = subprocess.run(['node', '--check', str(ROOT / 'scripts/enterprise-auth' / n)], capture_output=True)
  25. assert result.returncode == 0, 'JAVASCRIPT_CHECK_FAILED'
  26. files['validation.json'] = encode(validation)
  27. files['source-info.json'] = encode({
  28. 'schema': 'ksf.enterprise-workshop-auth-support-source.v1',
  29. 'targetContainer': 'agent-node-kangshifu', 'targetHost': '6f03725e5dc8',
  30. 'companyObjectId': 'FKieRbIoGt', 'appId': 'FKieRbIoGt_main',
  31. 'configurationRepositoryCommitPreserved': '262151d448482f940938ae234505276a60f4c58b',
  32. 'wrapperSha256': sha((ROOT / 'skills/ksf-workshop-runtime/scripts/ksf-secure.mjs').read_bytes()),
  33. 'adminIssuerIncluded': False, 'credentialsIncluded': False,
  34. 'credentialIssuedInProduction': False, 'productionBindingInstalled': False,
  35. })
  36. files['FILES.sha256'] = ''.join(sha(raw) + ' ' + n + '\n' for n, raw in sorted(files.items())).encode()
  37. for n, raw in files.items():
  38. dest = OUT / 'package' / n
  39. dest.parent.mkdir(parents=True, exist_ok=True)
  40. dest.write_bytes(raw)
  41. stream = io.BytesIO()
  42. with zipfile.ZipFile(stream, 'w', zipfile.ZIP_DEFLATED) as z:
  43. for name, raw in sorted(files.items()):
  44. entry = zipfile.ZipInfo(name, (2026, 11, 10, 0, 0, 0))
  45. entry.external_attr = 0o100644 << 16
  46. z.writestr(entry, raw, compress_type=zipfile.ZIP_DEFLATED)
  47. archive = stream.getvalue()
  48. (OUT / (NAME + '.zip')).write_bytes(archive)
  49. release = {'release': NAME, 'archive': NAME + '.zip', 'bytes': len(archive), 'sha256': sha(archive),
  50. 'files': len(files), 'manifestEntries': len(files) - 1, 'credentialsIncluded': False,
  51. 'skillModified': False, 'productionCredentialIssued': False, 'businessWrites': 0}
  52. (OUT / 'release.json').write_bytes(encode(release))
  53. print(json.dumps(release, ensure_ascii=False, indent=2))
  54. if __name__ == '__main__':
  55. main()