idea208-canticle-poetic-policy/canticle.py

26 lines
874 B
Python

import json
import hashlib
class CanticlePolicy:
def __init__(self, name, scopes):
self.name = name
self.scopes = scopes # list of strings like "network:egress:allow"
def to_json(self):
return json.dumps({"name": self.name, "scopes": self.scopes}, sort_keys=True)
def fingerprint(self):
return hashlib.sha256(self.to_json().encode()).hexdigest()
def generate_poem(self):
# A simple poetic summary generator for the policy
lines = [f"The canticle of {self.name} resonates:"]
for scope in self.scopes:
lines.append(f" Enshrined: {scope}")
lines.append(f"Witnessed at {self.fingerprint()[:8]}")
return "\n".join(lines)
if __name__ == "__main__":
p = CanticlePolicy("MastermanGate", ["network:egress:allow", "filesystem:read:restricted"])
print(p.generate_poem())