rezabarkhordary commited on
Commit
98a205d
·
verified ·
1 Parent(s): 1f303e0

Create sovereign_deployment_report.py

Browse files
Files changed (1) hide show
  1. sovereign_deployment_report.py +291 -0
sovereign_deployment_report.py ADDED
@@ -0,0 +1,291 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # sovereign_deployment_report.py
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import os
7
+ from datetime import datetime, timezone
8
+ from typing import Any, Dict, List, Optional
9
+
10
+ from sovereign_deployment_profile import generate_deployment_profile
11
+
12
+
13
+ DEPLOYMENT_OUTPUT_DIR = "sovereign_deployment_outputs"
14
+
15
+
16
+ def _utc_now() -> str:
17
+ return datetime.now(timezone.utc).isoformat()
18
+
19
+
20
+ def _ensure_dir(path: str) -> None:
21
+ os.makedirs(path, exist_ok=True)
22
+
23
+
24
+ def _safe(v: Any, default: Any = "") -> Any:
25
+ return v if v is not None else default
26
+
27
+
28
+ def _bool_text(v: Any) -> str:
29
+ return "True" if bool(v) else "False"
30
+
31
+
32
+ def _render_header(bundle: Dict[str, Any]) -> str:
33
+ profile = bundle.get("deployment_profile", {}) if isinstance(bundle, dict) else {}
34
+
35
+ return f"""# Sovereign Deployment Report
36
+
37
+ Generated at: {_safe((profile or {}).get("generated_at"), _utc_now())}
38
+
39
+ ## 1. Profile Identity
40
+ - Profile Type: {_safe(profile.get("profile_type"), "Sovereign Deployment Profile")}
41
+ - Domain: {_safe(profile.get("domain"), "banking_and_financial_institutions")}
42
+ """
43
+
44
+
45
+ def _render_summary(bundle: Dict[str, Any]) -> str:
46
+ profile = bundle.get("deployment_profile", {}) if isinstance(bundle, dict) else {}
47
+ summary = profile.get("summary", {}) if isinstance(profile, dict) else {}
48
+
49
+ return f"""## 2. Executive Summary
50
+ - Supported Primary Mode: {_safe(summary.get("supported_primary_mode"), "unknown")}
51
+ - Runtime Entrypoint Defined: {_bool_text(summary.get("runtime_entrypoint_defined"))}
52
+ - One-Command Launcher Present: {_bool_text(summary.get("one_command_launcher_present"))}
53
+ - Internet Dependency Required: {_bool_text(summary.get("internet_dependency_required"))}
54
+ - Cloud Dependency Required: {_bool_text(summary.get("cloud_dependency_required"))}
55
+
56
+ ### Practical Interpretation
57
+ - Sovereign is currently positioned for controlled bank-grade runtime deployment.
58
+ - On-prem / customer-controlled execution is the primary intended deployment posture.
59
+ - One-command launch is available in qualified form through the launcher/config path.
60
+ - Low-friction deployment does not mean universal zero-touch installation across all bank environments.
61
+ """
62
+
63
+
64
+ def _render_modes(bundle: Dict[str, Any]) -> str:
65
+ profile = bundle.get("deployment_profile", {}) if isinstance(bundle, dict) else {}
66
+ modes = profile.get("deployment_modes", []) if isinstance(profile, dict) else []
67
+
68
+ lines: List[str] = ["## 3. Deployment Modes"]
69
+
70
+ if not modes:
71
+ lines.append("- No deployment modes recorded.")
72
+ return "\n".join(lines)
73
+
74
+ for item in modes:
75
+ intended = item.get("intended_use", [])
76
+ lines.append(f"### {item.get('mode', 'unknown_mode')}")
77
+ lines.append(f"- Status: {_safe(item.get('status'))}")
78
+ lines.append(f"- Description: {_safe(item.get('description'))}")
79
+ if intended:
80
+ lines.append("- Intended Use:")
81
+ for x in intended:
82
+ lines.append(f" - {x}")
83
+ lines.append("")
84
+
85
+ return "\n".join(lines).rstrip() + "\n"
86
+
87
+
88
+ def _render_environment_requirements(bundle: Dict[str, Any]) -> str:
89
+ profile = bundle.get("deployment_profile", {}) if isinstance(bundle, dict) else {}
90
+ env = profile.get("environment_requirements", {}) if isinstance(profile, dict) else {}
91
+
92
+ runtime_req = env.get("runtime_requirements", {}) if isinstance(env, dict) else {}
93
+ network_req = env.get("network_requirements", {}) if isinstance(env, dict) else {}
94
+ execution_req = env.get("execution_requirements", {}) if isinstance(env, dict) else {}
95
+ artifact_req = env.get("artifact_requirements", {}) if isinstance(env, dict) else {}
96
+
97
+ return f"""## 4. Environment Requirements
98
+
99
+ ### Runtime Requirements
100
+ - Python Runtime Required: {_bool_text(runtime_req.get("python_runtime_required"))}
101
+ - Filesystem Write Required: {_bool_text(runtime_req.get("filesystem_write_required"))}
102
+ - JSON Artifact Support Required: {_bool_text(runtime_req.get("json_artifact_support_required"))}
103
+ - Local Execution Supported: {_bool_text(runtime_req.get("local_execution_supported"))}
104
+
105
+ ### Network Requirements
106
+ - Internet Required: {_bool_text(network_req.get("internet_required"))}
107
+ - Cloud Dependency Required: {_bool_text(network_req.get("cloud_dependency_required"))}
108
+ - External DNS Required: {_bool_text(network_req.get("external_dns_required"))}
109
+ - Offline Posture Supported: {_bool_text(network_req.get("offline_posture_supported"))}
110
+
111
+ ### Execution Requirements
112
+ - Single Entrypoint Defined: {_bool_text(execution_req.get("single_entrypoint_defined"))}
113
+ - Runtime Entry Module: {_safe(execution_req.get("runtime_entry_module"))}
114
+ - Runtime Entry Function: {_safe(execution_req.get("runtime_entry_function"))}
115
+ - Launcher Module: {_safe(execution_req.get("one_command_launcher_module"))}
116
+ - Config-Driven Launch Supported: {_bool_text(execution_req.get("config_driven_launch_supported"))}
117
+
118
+ ### Artifact Requirements
119
+ - Audit Chain Storage Required: {_bool_text(artifact_req.get("audit_chain_storage_required"))}
120
+ - Crypto Seal Support Required: {_bool_text(artifact_req.get("crypto_seal_support_required"))}
121
+ - Manifest Generation Required: {_bool_text(artifact_req.get("manifest_generation_required"))}
122
+ - Verifier Compatibility Expected: {_bool_text(artifact_req.get("verifier_compatibility_expected"))}
123
+ """
124
+
125
+
126
+ def _render_packaging_posture(bundle: Dict[str, Any]) -> str:
127
+ profile = bundle.get("deployment_profile", {}) if isinstance(bundle, dict) else {}
128
+ packaging = profile.get("packaging_posture", {}) if isinstance(profile, dict) else {}
129
+
130
+ notes = packaging.get("packaging_notes", []) if isinstance(packaging, dict) else []
131
+
132
+ lines = [
133
+ "## 5. Packaging Posture",
134
+ f"- Current Packaging State: {_safe(packaging.get('current_packaging_state'))}",
135
+ f"- Runtime Package Builder: {_safe(packaging.get('runtime_package_builder'))}",
136
+ f"- One-Command Launcher Available: {_bool_text(packaging.get('one_command_launcher_available'))}",
137
+ ]
138
+
139
+ if notes:
140
+ lines.append("- Packaging Notes:")
141
+ for item in notes:
142
+ lines.append(f" - {item}")
143
+
144
+ return "\n".join(lines)
145
+
146
+
147
+ def _render_frictionless_claim(bundle: Dict[str, Any]) -> str:
148
+ profile = bundle.get("deployment_profile", {}) if isinstance(bundle, dict) else {}
149
+ claim = profile.get("frictionless_deployment_claim", {}) if isinstance(profile, dict) else {}
150
+
151
+ meaning = claim.get("meaning", []) if isinstance(claim, dict) else []
152
+ non_meaning = claim.get("non_meaning", []) if isinstance(claim, dict) else []
153
+
154
+ lines = [
155
+ "## 6. Low-Friction Deployment Claim",
156
+ f"- Claim Label: {_safe(claim.get('claim_label'))}",
157
+ f"- Status: {_safe(claim.get('status'))}",
158
+ ]
159
+
160
+ if meaning:
161
+ lines.append("- Meaning:")
162
+ for item in meaning:
163
+ lines.append(f" - {item}")
164
+
165
+ if non_meaning:
166
+ lines.append("- Non-Meaning / Explicit Limits:")
167
+ for item in non_meaning:
168
+ lines.append(f" - {item}")
169
+
170
+ return "\n".join(lines)
171
+
172
+
173
+ def _render_constraints(bundle: Dict[str, Any]) -> str:
174
+ profile = bundle.get("deployment_profile", {}) if isinstance(bundle, dict) else {}
175
+ constraints = profile.get("constraints", []) if isinstance(profile, dict) else []
176
+
177
+ lines = ["## 7. Constraints"]
178
+
179
+ if not constraints:
180
+ lines.append("- No constraints recorded.")
181
+ return "\n".join(lines)
182
+
183
+ for item in constraints:
184
+ lines.append(f"- {item}")
185
+
186
+ return "\n".join(lines)
187
+
188
+
189
+ def _render_artifact_status(bundle: Dict[str, Any]) -> str:
190
+ seal = bundle.get("crypto_seal", {}) if isinstance(bundle, dict) else {}
191
+
192
+ return f"""## 8. Artifact Status
193
+ - Sealed: {bool(bundle.get("sealed", False))}
194
+ - Seal Digest: {_safe(seal.get("seal_digest"), "")}
195
+ - Seal Scheme: {_safe(seal.get("scheme"), "")}
196
+ - Seal Algorithm: {_safe(seal.get("algorithm"), "")}
197
+ - Signer Hint: {_safe(seal.get("signer_hint"), "")}
198
+ """
199
+
200
+
201
+ def _render_verdict(bundle: Dict[str, Any]) -> str:
202
+ profile = bundle.get("deployment_profile", {}) if isinstance(bundle, dict) else {}
203
+ constraints = profile.get("constraints", []) if isinstance(profile, dict) else []
204
+
205
+ verdict = (
206
+ "Sovereign currently presents a credible controlled deployment posture for bank-grade runtime use: "
207
+ "primary positioning is on-prem / customer-controlled runtime, offline-compatible execution is supported, "
208
+ "and one-command launch exists in qualified form through the launcher/config path."
209
+ )
210
+
211
+ lines = [
212
+ "## 9. Preliminary Bank-Facing Verdict",
213
+ verdict,
214
+ "",
215
+ "## 10. Notes",
216
+ ]
217
+
218
+ if constraints:
219
+ for item in constraints:
220
+ lines.append(f"- {item}")
221
+ else:
222
+ lines.append("- No additional notes provided.")
223
+
224
+ return "\n".join(lines)
225
+
226
+
227
+ def build_deployment_markdown(bundle: Dict[str, Any]) -> str:
228
+ parts = [
229
+ _render_header(bundle),
230
+ _render_summary(bundle),
231
+ _render_modes(bundle),
232
+ _render_environment_requirements(bundle),
233
+ _render_packaging_posture(bundle),
234
+ _render_frictionless_claim(bundle),
235
+ _render_constraints(bundle),
236
+ _render_artifact_status(bundle),
237
+ _render_verdict(bundle),
238
+ ]
239
+ return "\n\n".join(parts).strip() + "\n"
240
+
241
+
242
+ def save_deployment_report(
243
+ bundle: Dict[str, Any],
244
+ output_dir: str = DEPLOYMENT_OUTPUT_DIR,
245
+ base_name: Optional[str] = None,
246
+ ) -> Dict[str, str]:
247
+ _ensure_dir(output_dir)
248
+
249
+ ts = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
250
+ base = base_name or f"sovereign_deployment_report_{ts}"
251
+
252
+ json_path = os.path.join(output_dir, f"{base}.json")
253
+ md_path = os.path.join(output_dir, f"{base}.md")
254
+
255
+ with open(json_path, "w", encoding="utf-8") as f:
256
+ json.dump(bundle, f, ensure_ascii=False, indent=2)
257
+
258
+ markdown = build_deployment_markdown(bundle)
259
+ with open(md_path, "w", encoding="utf-8") as f:
260
+ f.write(markdown)
261
+
262
+ return {
263
+ "json_report": json_path,
264
+ "markdown_report": md_path,
265
+ }
266
+
267
+
268
+ def generate_deployment_report(
269
+ output_dir: str = DEPLOYMENT_OUTPUT_DIR,
270
+ base_name: Optional[str] = None,
271
+ ) -> Dict[str, Any]:
272
+ bundle = generate_deployment_profile()
273
+
274
+ files = save_deployment_report(
275
+ bundle=bundle,
276
+ output_dir=output_dir,
277
+ base_name=base_name,
278
+ )
279
+
280
+ return {
281
+ "ok": True,
282
+ "generated_at": _utc_now(),
283
+ "bundle": bundle,
284
+ "files": files,
285
+ }
286
+
287
+
288
+ if __name__ == "__main__":
289
+ out = generate_deployment_report()
290
+ print(json.dumps(out, indent=2, ensure_ascii=False))
291
+