smjain commited on
Commit
6393586
·
verified ·
1 Parent(s): ef678c8

Upload arch_rules.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. arch_rules.py +84 -0
arch_rules.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """SAP architecture best-practice rules, ported from the PAA architecture-validator
3
+ (github.tools.sap/platform-adoption-advisory/architecture-validator, input/rules.json
4
+ + src/rules/*.ts). Run directly on our clean semantic spec (typed components +
5
+ connections + nested blocks) — no SPARQL/OWL/LLM-recognizer needed."""
6
+
7
+ def _flat(spec):
8
+ """Return [(label_lower, id, [ancestor_block_labels_lower])] for all components."""
9
+ out = []
10
+ def walk(blocks, anc):
11
+ for b in blocks:
12
+ la = anc + [(b.get("label") or "").lower()]
13
+ for c in b.get("components", []):
14
+ out.append((c["label"].lower(), c["id"], la))
15
+ walk(b.get("blocks", []), la)
16
+ walk(spec.get("blocks", []), [])
17
+ return out
18
+
19
+ def _has(comps, *kw):
20
+ return any(any(k in lbl for k in kw) for lbl, _, _ in comps)
21
+
22
+ def _ids(comps, *kw):
23
+ return [cid for lbl, cid, _ in comps if any(k in lbl for k in kw)]
24
+
25
+ LLM_KW = ("gpt", "llm", "openai", "open ai", "generative ai", "claude", "gemini",
26
+ "anthropic", "foundation model", "large language model", "mistral", "llama")
27
+ HUB_KW = ("generative ai hub", "ai core")
28
+ IDP_KW = ("azure ad", "azure active directory", "entra", "okta", "ping identity",
29
+ "auth0", "3rd party identity", "third party identity", "external identity provider")
30
+ IAS_KW = ("cloud identity services", "identity authentication", "identity provisioning", "ias")
31
+ BUILD_KW = ("build process automation", "build apps", "build work zone", "build workzone",
32
+ "business application studio", "build code")
33
+ ONPREM_KW = ("s/4hana", "s4hana", "sap ecc", "on-premise", "on premise")
34
+ EVENT_KW = ("event mesh", "advanced event mesh", "event hub", "cloud application event hub")
35
+
36
+ def check_rules(spec):
37
+ """Return a list of best-practice violations (empty = compliant)."""
38
+ c = _flat(spec)
39
+ v = []
40
+
41
+ # R6: GenAI/LLM must be consumed via SAP Generative AI Hub / SAP AI Core
42
+ if _has(c, *LLM_KW) and not _has(c, *HUB_KW):
43
+ v.append("GenAI/LLM service present but not via SAP Generative AI Hub or SAP AI Core "
44
+ "(add 'SAP Generative AI Hub').")
45
+ # R12: AI Core / Gen AI Hub require a management interface
46
+ if _has(c, "ai core", "generative ai hub") and not _has(c, "ai launchpad", "ai core api"):
47
+ v.append("SAP AI Core/Generative AI Hub present but no management interface "
48
+ "(add 'SAP AI Launchpad').")
49
+ # R5: custom ML models must be managed via AI Core
50
+ if _has(c, "custom model", "ml model", "machine learning model", "trained model") and not _has(c, "ai core"):
51
+ v.append("Custom ML model present but not managed via SAP AI Core.")
52
+ # R4: external IdPs must go through SAP Cloud Identity Services (IAS)
53
+ if _has(c, *IDP_KW) and not _has(c, *IAS_KW):
54
+ v.append("External identity provider present but not integrated via SAP Cloud Identity "
55
+ "Services (add 'Identity Authentication').")
56
+ # R2: Copilot / AI agents must integrate via Joule
57
+ if _has(c, "copilot", "ai agent", "ai assistant") and not _has(c, "joule"):
58
+ v.append("Copilot/AI agent present but not integrated via SAP Joule.")
59
+ # R10: Joule must be contained within an SAP system superArea
60
+ for lbl, cid, anc in c:
61
+ if "joule" in lbl and not any(any(s in a for s in ("btp", "s/4", "s4hana", "cloud solution",
62
+ "on-premise", "sap")) for a in anc):
63
+ v.append("SAP Joule is not contained within an SAP system block.")
64
+ break
65
+ # R3: on-premise/S4 integration needs Cloud Connector or Private Link
66
+ if _has(c, *ONPREM_KW) and not _has(c, "cloud connector", "private link"):
67
+ v.append("S/4HANA / on-premise system present but no Cloud Connector or Private Link.")
68
+ # R1: CAP integrating to external systems needs a Destination service
69
+ if _has(c, "cloud application programming", "cap application", "(cap)") and not _has(c, "destination service"):
70
+ v.append("CAP application present but no SAP Destination service for external integration.")
71
+ # R14: Cloud Connector tunnels to the SAP Connectivity service (complete the secure chain)
72
+ if _has(c, "cloud connector") and not _has(c, "connectivity service"):
73
+ v.append("Cloud Connector present but no SAP Connectivity service (incomplete on-prem tunnel).")
74
+ # R13: event-driven architecture must use an SAP Event service
75
+ event_hint = any("event" in lbl for lbl, _, _ in c) or \
76
+ any("event" in (e.get("label","") or "").lower() for e in spec.get("connections", []))
77
+ if event_hint and not _has(c, *EVENT_KW):
78
+ v.append("Event-driven architecture but no SAP Event Mesh / Advanced Event Mesh / Event Hub.")
79
+ return v
80
+
81
+ if __name__ == "__main__":
82
+ import sys, json
83
+ spec = json.load(open(sys.argv[1]))
84
+ for x in check_rules(spec): print("VIOLATION:", x)