@tdk-landscape/tdk-cli-core 1.3.14 → 1.3.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (277) hide show
  1. package/README.md +3 -3
  2. package/Tiltfile +144 -0
  3. package/discovery/AGENTS.md +362 -0
  4. package/discovery/TILT_DISCOVERY.star +424 -0
  5. package/discovery/Tiltfile +58 -0
  6. package/discovery/config.star +258 -0
  7. package/discovery/constants.star +127 -0
  8. package/discovery/deterministic.star +211 -0
  9. package/discovery/discovery_daemon.star +191 -0
  10. package/discovery/discovery_orchestrator.star +460 -0
  11. package/discovery/filtering.star +5 -0
  12. package/discovery/identity-management-backend/service.yaml +26 -0
  13. package/discovery/identity-management-frontend/service.yaml +29 -0
  14. package/discovery/identity-sdk/service.yaml +9 -0
  15. package/discovery/incremental_discovery.star +213 -0
  16. package/discovery/indexing.star +7 -0
  17. package/discovery/json_manifest_scanner.star +51 -0
  18. package/discovery/libraries.star +46 -0
  19. package/discovery/loading.star +23 -0
  20. package/discovery/manifest/constants.star +104 -0
  21. package/discovery/manifest/loading.star +386 -0
  22. package/discovery/manifest/normalize.star +281 -0
  23. package/discovery/manifest/validation.star +108 -0
  24. package/discovery/normalization.star +11 -0
  25. package/discovery/registry.star +544 -0
  26. package/discovery/resource_snapshot.py +382 -0
  27. package/discovery/resource_snapshot.star +143 -0
  28. package/discovery/schemas.star +1 -0
  29. package/discovery/services/platform/cdc/debezium/nats-connector/service.yaml +9 -0
  30. package/discovery/services/platform/cdc/nats-http-bridge/service.yaml +9 -0
  31. package/discovery/services/platform/orchestrator/orchestrator-glue-backend/service.yaml +26 -0
  32. package/discovery/services/platform/synthetic-monitor/service.yaml +9 -0
  33. package/discovery/test_resource_snapshot.py +251 -0
  34. package/discovery/validation.star +78 -0
  35. package/discovery/versioning.star +1 -0
  36. package/dist/commands/config.d.ts.map +1 -1
  37. package/dist/commands/config.js +11 -0
  38. package/dist/commands/config.js.map +1 -1
  39. package/dist/commands/doctor.d.ts.map +1 -1
  40. package/dist/commands/doctor.js +1 -2
  41. package/dist/commands/doctor.js.map +1 -1
  42. package/dist/commands/project.d.ts.map +1 -1
  43. package/dist/commands/project.js +36 -41
  44. package/dist/commands/project.js.map +1 -1
  45. package/dist/commands/resource.d.ts.map +1 -1
  46. package/dist/commands/resource.js +51 -55
  47. package/dist/commands/resource.js.map +1 -1
  48. package/dist/commands/stack.d.ts.map +1 -1
  49. package/dist/commands/stack.js +22 -24
  50. package/dist/commands/stack.js.map +1 -1
  51. package/dist/commands/ui.d.ts.map +1 -1
  52. package/dist/commands/ui.js +1 -2
  53. package/dist/commands/ui.js.map +1 -1
  54. package/dist/commands/up.d.ts.map +1 -1
  55. package/dist/commands/up.js +1 -2
  56. package/dist/commands/up.js.map +1 -1
  57. package/dist/commands/upgrade.d.ts +8 -0
  58. package/dist/commands/upgrade.d.ts.map +1 -1
  59. package/dist/commands/upgrade.js +62 -21
  60. package/dist/commands/upgrade.js.map +1 -1
  61. package/dist/generator/extension-fetch.d.ts +19 -0
  62. package/dist/generator/extension-fetch.d.ts.map +1 -1
  63. package/dist/generator/extension-fetch.js +71 -5
  64. package/dist/generator/extension-fetch.js.map +1 -1
  65. package/dist/generator/template-engine.d.ts +1 -0
  66. package/dist/generator/template-engine.d.ts.map +1 -1
  67. package/dist/generator/template-engine.js +50 -6
  68. package/dist/generator/template-engine.js.map +1 -1
  69. package/dist/utils/command-helpers.d.ts.map +1 -1
  70. package/dist/utils/command-helpers.js +7 -9
  71. package/dist/utils/command-helpers.js.map +1 -1
  72. package/dist/utils/constants.d.ts +1 -0
  73. package/dist/utils/constants.d.ts.map +1 -1
  74. package/dist/utils/constants.js +1 -0
  75. package/dist/utils/constants.js.map +1 -1
  76. package/dist/utils/errors.d.ts +2 -0
  77. package/dist/utils/errors.d.ts.map +1 -1
  78. package/dist/utils/errors.js +6 -1
  79. package/dist/utils/errors.js.map +1 -1
  80. package/dist/utils/paths.js +1 -1
  81. package/dist/utils/paths.js.map +1 -1
  82. package/dist/utils/project-features.d.ts.map +1 -1
  83. package/dist/utils/project-features.js +1 -1
  84. package/dist/utils/project-features.js.map +1 -1
  85. package/dist/utils/resource-features.d.ts.map +1 -1
  86. package/dist/utils/resource-features.js +2 -2
  87. package/dist/utils/resource-features.js.map +1 -1
  88. package/dist/utils/tar.js +4 -4
  89. package/dist/utils/tar.js.map +1 -1
  90. package/dist/utils/validation.d.ts +7 -0
  91. package/dist/utils/validation.d.ts.map +1 -1
  92. package/dist/utils/validation.js +9 -0
  93. package/dist/utils/validation.js.map +1 -1
  94. package/engine/AGENTS.md +705 -0
  95. package/engine/README.md +29 -0
  96. package/engine/REFACTORING_MANIFEST_SYSTEM.md +974 -0
  97. package/engine/Tiltfile +80 -0
  98. package/engine/assets/docker/golden-layers.Dockerfile +221 -0
  99. package/engine/assets/scripts/cleanup-completed-migrator-images.sh +37 -0
  100. package/engine/assets/scripts/cleanup-tilt-images.sh +120 -0
  101. package/engine/assets/scripts/mac-m1-resource-monitor.sh +121 -0
  102. package/engine/config.star +3 -0
  103. package/engine/docs/AUTODISCOVERY_TEST.md +182 -0
  104. package/engine/docs/C4-ARCHITECTURE-operations.md +396 -0
  105. package/engine/docs/C4-ARCHITECTURE-overview.md +284 -0
  106. package/engine/docs/C4-ARCHITECTURE.md +17 -0
  107. package/engine/docs/GOLDEN_IMAGE_INTEGRATION.md +349 -0
  108. package/engine/docs/MANIFEST_DRIVEN_ARCHITECTURE.md +357 -0
  109. package/engine/docs/README.md +284 -0
  110. package/engine/entrypoint.star +97 -0
  111. package/engine/lifecycle/orchestrator.star +260 -0
  112. package/engine/paths.star +717 -0
  113. package/engine/schemas/manifest-schema.json +301 -0
  114. package/engine/schemas/service-schema.json +301 -0
  115. package/engine/scripts/README.md +89 -0
  116. package/engine/scripts/build-and-publish-lib.sh +205 -0
  117. package/engine/scripts/check-lib-publish.sh +85 -0
  118. package/engine/scripts/debug-container.sh +258 -0
  119. package/engine/scripts/generate-manifest.sh +197 -0
  120. package/engine/spec.master +702 -0
  121. package/engine/spec.master.example +341 -0
  122. package/engine/topologies/README.md +34 -0
  123. package/engine/topologies/platform/docker/AGENTS.md +59 -0
  124. package/engine/topologies/platform/docker/auth/auth.star +167 -0
  125. package/engine/topologies/platform/docker/build/golden_image.star +37 -0
  126. package/engine/topologies/platform/docker/build/golden_image_build.star +82 -0
  127. package/engine/topologies/platform/docker/build/golden_image_constants.star +93 -0
  128. package/engine/topologies/platform/docker/build/golden_image_dockerfile.star +291 -0
  129. package/engine/topologies/platform/docker/compose/compose.star +636 -0
  130. package/engine/topologies/platform/docker/compose/compose_helpers.star +52 -0
  131. package/engine/topologies/platform/docker/compose/traefik_standalone.star +53 -0
  132. package/engine/topologies/platform/docker/config/bunignore.star +142 -0
  133. package/engine/topologies/platform/docker/config/dockerignore.star +150 -0
  134. package/engine/topologies/platform/docker/constants.star +170 -0
  135. package/engine/topologies/platform/docker/dockerfile/dockerfile.star +54 -0
  136. package/engine/topologies/platform/docker/generators/golden_docker_generator_v2.star +73 -0
  137. package/engine/topologies/platform/docker/index.star +27 -0
  138. package/engine/topologies/platform/docker/layers/bun_helpers.star +23 -0
  139. package/engine/topologies/platform/docker/layers/infisical/index.star +40 -0
  140. package/engine/topologies/platform/docker/layers/infisical/infisical_docker.star +262 -0
  141. package/engine/topologies/platform/docker/layers/l1_base_layers.star +87 -0
  142. package/engine/topologies/platform/docker/layers/l2_dependency_layers.star +125 -0
  143. package/engine/topologies/platform/docker/layers/l3_builder_layers.star +209 -0
  144. package/engine/topologies/platform/docker/layers/l4_runtime_layers.star +214 -0
  145. package/engine/topologies/platform/docker/layers/prisma/constants.star +135 -0
  146. package/engine/topologies/platform/docker/layers/prisma/db_readiness.star +96 -0
  147. package/engine/topologies/platform/docker/layers/prisma/filesystem_setup.star +109 -0
  148. package/engine/topologies/platform/docker/layers/prisma/migrate_script.star +98 -0
  149. package/engine/topologies/platform/docker/layers/prisma/prisma_build.star +126 -0
  150. package/engine/topologies/platform/docker/layers/prisma/prisma_runtime.star +161 -0
  151. package/engine/topologies/platform/docker/layers/prisma/secret_resolution.star +119 -0
  152. package/engine/topologies/platform/docker/networking/api_path_constants.star +230 -0
  153. package/engine/topologies/platform/docker/networking/sablier_container_cycle.star +27 -0
  154. package/engine/topologies/platform/docker/networking/traefik.star +232 -0
  155. package/engine/topologies/platform/docker/networking/traefik_constants.star +146 -0
  156. package/engine/topologies/platform/docker/networking/traefik_helpers.star +160 -0
  157. package/engine/topologies/platform/docker/secrets/infisical.star +135 -0
  158. package/engine/topologies/platform/net/proxy.star +4 -0
  159. package/engine/topologies/platform/registries/local.star +4 -0
  160. package/engine/topologies/platform/security/secrets.star +239 -0
  161. package/engine/topologies/platform/state/relational.star +4 -0
  162. package/engine/topologies/tilt/common/AGENTS.md +59 -0
  163. package/engine/topologies/tilt/common/utils.star +364 -0
  164. package/engine/topologies/tilt/common/utils_debug.star +69 -0
  165. package/engine/topologies/tilt/common/utils_deterministic.star +168 -0
  166. package/engine/topologies/tilt/common/utils_docker_networks.star +46 -0
  167. package/engine/topologies/tilt/common/utils_env.star +43 -0
  168. package/engine/topologies/tilt/common/utils_output.star +97 -0
  169. package/engine/topologies/tilt/config/AGENTS.md +68 -0
  170. package/engine/topologies/tilt/config/defaults.star +3 -0
  171. package/engine/topologies/tilt/config/feature_flags.star +10 -0
  172. package/engine/topologies/tilt/config/global.star +55 -0
  173. package/engine/topologies/tilt/config/profiles.star +382 -0
  174. package/engine/topologies/tilt/generators/agents_md.star +62 -0
  175. package/engine/topologies/tilt/generators/api_gateway.star +145 -0
  176. package/engine/topologies/tilt/generators/index.star +124 -0
  177. package/engine/topologies/tilt/generators/infisical/README.md +424 -0
  178. package/engine/topologies/tilt/generators/infisical/examples.star +312 -0
  179. package/engine/topologies/tilt/generators/infisical/index.star +57 -0
  180. package/engine/topologies/tilt/generators/infisical/machine_identity.star +420 -0
  181. package/engine/topologies/tilt/generators/infisical/organization.star +534 -0
  182. package/engine/topologies/tilt/generators/infisical/path_manager.star +476 -0
  183. package/engine/topologies/tilt/generators/infisical/secrets_generator.star +420 -0
  184. package/engine/topologies/tilt/generators/nginx_conf.star +143 -0
  185. package/engine/topologies/tilt/generators/npmrc.star +111 -0
  186. package/engine/topologies/tilt/generators/tsconfig.star +23 -0
  187. package/engine/topologies/tilt/generators/typescript/backend_library_tsconfig.star +71 -0
  188. package/engine/topologies/tilt/generators/typescript/backend_tsconfig.star +124 -0
  189. package/engine/topologies/tilt/generators/typescript/common.star +7 -0
  190. package/engine/topologies/tilt/generators/typescript/frontend_library_tsconfig.star +76 -0
  191. package/engine/topologies/tilt/generators/typescript/frontend_tsconfig.star +110 -0
  192. package/engine/topologies/tilt/generators/typescript/include.star +23 -0
  193. package/engine/topologies/tilt/generators/typescript/playwright_config.star +40 -0
  194. package/engine/topologies/tilt/generators/typescript/prisma_config.star +49 -0
  195. package/engine/topologies/tilt/generators/validators.star +853 -0
  196. package/engine/topologies/tilt/generators/vite/backend.star +78 -0
  197. package/engine/topologies/tilt/generators/vite/frontend.star +98 -0
  198. package/engine/topologies/tilt/generators/vite/generators.star +43 -0
  199. package/engine/topologies/tilt/generators/vite/helpers.star +244 -0
  200. package/engine/topologies/tilt/generators/vite/library.star +65 -0
  201. package/engine/topologies/tilt/generators/vite/sdk.star +73 -0
  202. package/engine/topologies/tilt/generators/vite/templates.star +737 -0
  203. package/engine/topologies/tilt/generators/vite_config.star +22 -0
  204. package/engine/topologies/tilt/manifest/AGENTS.md +61 -0
  205. package/engine/topologies/tilt/manifest/README.md +693 -0
  206. package/engine/topologies/tilt/manifest/__init__.star +218 -0
  207. package/engine/topologies/tilt/manifest/constants.star +252 -0
  208. package/engine/topologies/tilt/manifest/errors.star +266 -0
  209. package/engine/topologies/tilt/manifest/integration.star +339 -0
  210. package/engine/topologies/tilt/manifest/json_to_yaml.py +54 -0
  211. package/engine/topologies/tilt/manifest/loader.star +214 -0
  212. package/engine/topologies/tilt/manifest/mapper.star +227 -0
  213. package/engine/topologies/tilt/manifest/parser.star +400 -0
  214. package/engine/topologies/tilt/manifest/schema.star +462 -0
  215. package/engine/topologies/tilt/manifest/tests/test_integration.star +276 -0
  216. package/engine/topologies/tilt/manifest/tests/test_loader_parser.star +397 -0
  217. package/engine/topologies/tilt/manifest/tests/test_manifest.star +316 -0
  218. package/engine/topologies/tilt/manifest/tests/test_validator.star +470 -0
  219. package/engine/topologies/tilt/manifest/validator.star +717 -0
  220. package/engine/topologies/tilt/manifest/yaml_to_json.py +18 -0
  221. package/engine/topologies/tilt/resources/AGENTS.md +71 -0
  222. package/engine/topologies/tilt/resources/conditions.star +3 -0
  223. package/engine/topologies/tilt/resources/databases.star +244 -0
  224. package/engine/topologies/tilt/resources/declaration.star +3 -0
  225. package/engine/topologies/tilt/resources/deps.star +3 -0
  226. package/engine/topologies/tilt/resources/infra-loader.star +437 -0
  227. package/engine/topologies/tilt/resources/libs.star +30 -0
  228. package/engine/topologies/tilt/resources/libs_discovery.star +102 -0
  229. package/engine/topologies/tilt/resources/libs_paths.star +79 -0
  230. package/engine/topologies/tilt/resources/libs_resource_definition.star +151 -0
  231. package/engine/topologies/tilt/resources/libs_setup.star +164 -0
  232. package/engine/topologies/tilt/resources/libs_tsconfig.star +37 -0
  233. package/engine/topologies/tilt/resources/orchestrator/apply.star +77 -0
  234. package/engine/topologies/tilt/resources/orchestrator/apply_compose_resource_registration.star +431 -0
  235. package/engine/topologies/tilt/resources/orchestrator/apply_manifest_orchestration.star +81 -0
  236. package/engine/topologies/tilt/resources/orchestrator/apply_migrator_orchestration.star +148 -0
  237. package/engine/topologies/tilt/resources/orchestrator/apply_resource_validation.star +36 -0
  238. package/engine/topologies/tilt/resources/orchestrator/apply_runtime_flags.star +44 -0
  239. package/engine/topologies/tilt/resources/orchestrator/builders/typescript.star +164 -0
  240. package/engine/topologies/tilt/resources/orchestrator/generators/dependencies/AGENTS.md +75 -0
  241. package/engine/topologies/tilt/resources/orchestrator/generators/dependencies/index.star +21 -0
  242. package/engine/topologies/tilt/resources/orchestrator/generators/dependencies/resolver.star +134 -0
  243. package/engine/topologies/tilt/resources/orchestrator/generators/env.star +258 -0
  244. package/engine/topologies/tilt/resources/orchestrator/generators/frontend.star +169 -0
  245. package/engine/topologies/tilt/resources/orchestrator/generators/manifest_resource.star +524 -0
  246. package/engine/topologies/tilt/resources/orchestrator/helpers.star +33 -0
  247. package/engine/topologies/tilt/resources/orchestrator.star +54 -0
  248. package/engine/topologies/tilt/resources/ordering.star +3 -0
  249. package/engine/topologies/tilt/resources/triggers.star +3 -0
  250. package/engine/topologies/tilt/resources/watchers.star +299 -0
  251. package/engine/where-things-live.star +717 -0
  252. package/ext/Tiltfile +66 -0
  253. package/ext/ide-components/README.md +219 -0
  254. package/ext/ide-components/code_executor/server.py +268 -0
  255. package/ext/ide-components/code_viewer/server.py +206 -0
  256. package/ext/ide-components/config_inspector/server.py +1050 -0
  257. package/ext/ide-components/file_browser/server.py +285 -0
  258. package/ext/ide-components/shared/config_service.py +469 -0
  259. package/ext/ide-components/shared/file_utils.py +298 -0
  260. package/ext/ide-components/shared/http_utils.py +232 -0
  261. package/ext/ide-components/shared/static/styles.css +1334 -0
  262. package/ext/ide-components/shared/syntax_highlighter.py +140 -0
  263. package/ext/ide-components/shared/template_engine.py +123 -0
  264. package/ext/ide-components/shared/templates/base.html +121 -0
  265. package/ext/ide-components/shared/test_config_service.py +326 -0
  266. package/ext/ide-components/shared/tilt_integration.py +158 -0
  267. package/ext/ui-enhancements/cron-status-server.sh +49 -0
  268. package/ext/ui-enhancements/cron-status-tracker.sh +146 -0
  269. package/ext/ui-enhancements/extension.yaml +36 -0
  270. package/ext/ui-enhancements/tiltfile.py +99 -0
  271. package/ext/ui-enhancements/ui/cron-jobs-tab.css +396 -0
  272. package/ext/ui-enhancements/ui/help-panel.css +279 -0
  273. package/ext/ui-enhancements/ui/icons.css +125 -0
  274. package/ext/ui-enhancements/ui/tooltips.css +114 -0
  275. package/package.json +13 -9
  276. package/specs/specs/TILT_SERVICE_DEFAULTS.star +205 -0
  277. package/specs/specs/TILT_TECH_STACK.star +159 -0
@@ -0,0 +1,476 @@
1
+ # =============================================================================
2
+ # 📁 INFISICAL PATH MANAGER
3
+ # =============================================================================
4
+ # Manages Infisical folder/path creation and organization
5
+ # Replaces: Shell scripts for creating folders via CLI
6
+ # =============================================================================
7
+ #
8
+ # This module provides:
9
+ # - Folder/path structure definitions
10
+ # - Path validation and normalization
11
+ # - Batch path creation planning
12
+ # - Organization hierarchy management
13
+ #
14
+ # Usage:
15
+ # load("./infisical/path_manager.star", "PathManager")
16
+ # paths = PathManager.plan_resource_paths(["user", "order"])
17
+ # =============================================================================
18
+
19
+ def _get_timestamp():
20
+ """Get current timestamp string"""
21
+ return str(local("date +%Y-%m-%dT%H:%M:%S", quiet=True)).strip()
22
+
23
+ # =============================================================================
24
+ # Path Constants and Conventions
25
+ # =============================================================================
26
+
27
+ # Root paths in Infisical
28
+ ROOT_PATHS = {
29
+ "services": "/services",
30
+ "platform": "/platform",
31
+ "shared": "/shared",
32
+ "infrastructure": "/infrastructure",
33
+ }
34
+
35
+ # Standard sub-paths for services
36
+ RESOURCE_SUBPATHS = [
37
+ "", # Root service folder
38
+ "database",
39
+ "api-keys",
40
+ "tokens",
41
+ "external",
42
+ ]
43
+
44
+ # Platform service paths
45
+ PLATFORM_PATHS = {
46
+ "api-gateway": "/platform/api-gateway",
47
+ "database": "/platform/database",
48
+ "messaging": "/platform/messaging",
49
+ "observability": "/platform/observability",
50
+ "security": "/platform/security",
51
+ }
52
+
53
+ # Shared secrets paths
54
+ SHARED_PATHS = {
55
+ "database-credentials": "/shared/database-credentials",
56
+ "api-tokens": "/shared/api-tokens",
57
+ "encryption-keys": "/shared/encryption-keys",
58
+ "certificates": "/shared/certificates",
59
+ }
60
+
61
+ # Infrastructure paths
62
+ INFRASTRUCTURE_PATHS = {
63
+ "postgres": "/infrastructure/postgres",
64
+ "redis": "/infrastructure/redis",
65
+ "nats": "/infrastructure/nats",
66
+ "infisical": "/infrastructure/infisical",
67
+ "traefik": "/infrastructure/traefik",
68
+ }
69
+
70
+ # =============================================================================
71
+ # Path Validation
72
+ # =============================================================================
73
+
74
+ def _normalize_path(path):
75
+ """
76
+ Normalize a path to Infisical format.
77
+
78
+ Rules:
79
+ - Must start with /
80
+ - No trailing slash (except root "/")
81
+ - Lowercase
82
+ - No spaces
83
+ - No consecutive slashes
84
+
85
+ Args:
86
+ path: Raw path string
87
+
88
+ Returns:
89
+ Normalized path string
90
+ """
91
+ if not path:
92
+ return ""
93
+
94
+ # Lowercase
95
+ path = path.lower()
96
+
97
+ # Ensure leading slash
98
+ if not path.startswith("/"):
99
+ path = "/" + path
100
+
101
+ # Remove trailing slash (except for root)
102
+ if path != "/" and path.endswith("/"):
103
+ path = path[:-1]
104
+
105
+ # Replace spaces with hyphens
106
+ path = path.replace(" ", "-")
107
+
108
+ # Remove consecutive slashes
109
+ while "//" in path:
110
+ path = path.replace("//", "/")
111
+
112
+ return path
113
+
114
+ def _validate_path(path, strict=False):
115
+ """
116
+ Validate an Infisical path.
117
+
118
+ Args:
119
+ path: Path to validate
120
+ strict: If True, enforces stricter rules
121
+
122
+ Returns:
123
+ Dict with validation results:
124
+ {
125
+ "valid": bool,
126
+ "normalized": str,
127
+ "errors": [str],
128
+ "warnings": [str],
129
+ }
130
+ """
131
+ errors = []
132
+ warnings = []
133
+
134
+ if not path:
135
+ errors.append("Path cannot be empty")
136
+ return {"valid": False, "normalized": "", "errors": errors, "warnings": warnings}
137
+
138
+ normalized = _normalize_path(path)
139
+
140
+ # Ensure normalized is a string
141
+ if type(normalized) != "string":
142
+ normalized = str(normalized)
143
+
144
+ # Check valid characters
145
+ valid_chars = "abcdefghijklmnopqrstuvwxyz0123456789-_/"
146
+ invalid_chars = []
147
+ for i in range(len(normalized)):
148
+ c = normalized[i]
149
+ if c not in valid_chars:
150
+ invalid_chars.append(c)
151
+ if len(invalid_chars) > 0:
152
+ errors.append("Invalid characters: {}".format(invalid_chars))
153
+
154
+ # Check depth limit (Infisical max is 20)
155
+ parts = []
156
+ for p in normalized.split("/"):
157
+ if p:
158
+ parts.append(p)
159
+ if len(parts) > 20:
160
+ errors.append("Path depth {} exceeds maximum (20)".format(len(parts)))
161
+
162
+ # Check segment length (max 255 per segment)
163
+ for part in parts:
164
+ if len(part) > 255:
165
+ errors.append("Path segment '{}' too long (max 255)".format(part[:20]))
166
+
167
+ # Check total length
168
+ if len(normalized) > 1024:
169
+ errors.append("Path too long (max 1024 characters)")
170
+
171
+ # Strict mode checks
172
+ if strict:
173
+ # Must follow /services/ or /platform/ or /shared/ convention
174
+ if len(parts) >= 1 and parts[0] not in ["services", "platform", "shared", "infrastructure"]:
175
+ warnings.append("Path not under standard root (/services, /platform, /shared, /infrastructure)")
176
+
177
+ # Check for reserved names
178
+ reserved = [".git", ".env", "admin", "root", "system"]
179
+ for part in parts:
180
+ if part in reserved:
181
+ errors.append("Reserved name not allowed: '{}'".format(part))
182
+
183
+ return {
184
+ "valid": len(errors) == 0,
185
+ "normalized": normalized,
186
+ "errors": errors,
187
+ "warnings": warnings,
188
+ }
189
+
190
+ def _is_valid_path(path):
191
+ """Quick validation check."""
192
+ result = _validate_path(path)
193
+ return result["valid"]
194
+
195
+ # =============================================================================
196
+ # Path Planning
197
+ # =============================================================================
198
+
199
+ def _plan_resource_path(resource_name, resource_type="backend", parent_path=None):
200
+ """
201
+ Plan the Infisical path for a service.
202
+
203
+ Args:
204
+ resource_name: Name of the service
205
+ resource_type: Type of service
206
+ parent_path: Optional custom parent path (default: /services)
207
+
208
+ Returns:
209
+ Dict with path plan
210
+ """
211
+ # Normalize service name for path
212
+ normalized_name = resource_name.lower().replace(" ", "-").replace("_", "-")
213
+
214
+ # Determine parent path
215
+ if parent_path:
216
+ parent = _normalize_path(parent_path)
217
+ elif resource_type == "platform":
218
+ parent = ROOT_PATHS["platform"]
219
+ elif resource_type == "infrastructure":
220
+ parent = ROOT_PATHS["infrastructure"]
221
+ else:
222
+ parent = ROOT_PATHS["services"]
223
+
224
+ # Build full path
225
+ full_path = "{}/{}".format(parent, normalized_name)
226
+
227
+ # Validate
228
+ validation = _validate_path(full_path, strict=True)
229
+
230
+ return {
231
+ "resource_name": resource_name,
232
+ "resource_type": resource_type,
233
+ "parent_path": parent,
234
+ "resource_folder": normalized_name,
235
+ "full_path": validation["normalized"],
236
+ "validation": validation,
237
+ "subpaths": ["{}/{}".format(validation["normalized"], sub) for sub in RESOURCE_SUBPATHS if sub],
238
+ }
239
+
240
+ def _plan_batch_resource_paths(resource_names, resource_type="backend", parent_path=None):
241
+ """
242
+ Plan paths for multiple services.
243
+
244
+ Args:
245
+ resource_names: List of service names
246
+ resource_type: Default type for all services
247
+ parent_path: Optional custom parent path
248
+
249
+ Returns:
250
+ Dict mapping service names to their path plans
251
+ """
252
+ results = {}
253
+
254
+ for name in resource_names:
255
+ results[name] = _plan_resource_path(name, resource_type, parent_path)
256
+
257
+ return results
258
+
259
+ def _plan_organization_structure(org_name, resource_names=None):
260
+ """
261
+ Plan complete organization folder structure.
262
+
263
+ Args:
264
+ org_name: Organization name
265
+ resource_names: List of service names to create under /services
266
+
267
+ Returns:
268
+ Dict with complete structure plan
269
+ """
270
+ structure = {
271
+ "organization": org_name,
272
+ "roots": {},
273
+ "services": {},
274
+ "platform": {},
275
+ "shared": {},
276
+ "infrastructure": {},
277
+ }
278
+
279
+ # Root paths
280
+ for name, path in ROOT_PATHS.items():
281
+ structure["roots"][name] = {
282
+ "path": path,
283
+ "purpose": _get_root_purpose(name),
284
+ }
285
+
286
+ # Platform paths
287
+ for name, path in PLATFORM_PATHS.items():
288
+ structure["platform"][name] = {
289
+ "path": path,
290
+ "purpose": _get_platform_purpose(name),
291
+ }
292
+
293
+ # Shared paths
294
+ for name, path in SHARED_PATHS.items():
295
+ structure["shared"][name] = {
296
+ "path": path,
297
+ "purpose": _get_shared_purpose(name),
298
+ }
299
+
300
+ # Infrastructure paths
301
+ for name, path in INFRASTRUCTURE_PATHS.items():
302
+ structure["infrastructure"][name] = {
303
+ "path": path,
304
+ "purpose": _get_infrastructure_purpose(name),
305
+ }
306
+
307
+ # Service paths
308
+ if resource_names:
309
+ structure["services"] = _plan_batch_resource_paths(resource_names)
310
+
311
+ return structure
312
+
313
+ def _get_root_purpose(name):
314
+ """Get description for root path."""
315
+ purposes = {
316
+ "services": "Application service secrets",
317
+ "platform": "Platform infrastructure secrets",
318
+ "shared": "Cross-service shared secrets",
319
+ "infrastructure": "Infrastructure component secrets",
320
+ }
321
+ return purposes.get(name, "General secrets")
322
+
323
+ def _get_platform_purpose(name):
324
+ """Get description for platform path."""
325
+ purposes = {
326
+ "api-gateway": "API Gateway configuration and tokens",
327
+ "database": "Database cluster credentials",
328
+ "messaging": "NATS and message broker secrets",
329
+ "observability": "Monitoring and logging secrets",
330
+ "security": "Security service secrets",
331
+ }
332
+ return purposes.get(name, "Platform service secrets")
333
+
334
+ def _get_shared_purpose(name):
335
+ """Get description for shared path."""
336
+ purposes = {
337
+ "database-credentials": "Shared database credentials",
338
+ "api-tokens": "Shared API tokens",
339
+ "encryption-keys": "Encryption and signing keys",
340
+ "certificates": "TLS certificates and keys",
341
+ }
342
+ return purposes.get(name, "Shared secrets")
343
+
344
+ def _get_infrastructure_purpose(name):
345
+ """Get description for infrastructure path."""
346
+ purposes = {
347
+ "postgres": "PostgreSQL cluster secrets",
348
+ "redis": "Redis cluster secrets",
349
+ "nats": "NATS server secrets",
350
+ "infisical": "Infisical self-secrets",
351
+ "traefik": "Traefik proxy secrets",
352
+ }
353
+ return purposes.get(name, "Infrastructure secrets")
354
+
355
+ # =============================================================================
356
+ # Path Operations
357
+ # =============================================================================
358
+
359
+ def _get_parent_path(path):
360
+ """Get parent path of a given path."""
361
+ normalized = _normalize_path(path)
362
+ parts = [p for p in normalized.split("/") if p]
363
+
364
+ if len(parts) <= 1:
365
+ return "/"
366
+
367
+ return "/" + "/".join(parts[:-1])
368
+
369
+ def _get_path_depth(path):
370
+ """Get depth of path (number of segments)."""
371
+ normalized = _normalize_path(path)
372
+ parts = [p for p in normalized.split("/") if p]
373
+ return len(parts)
374
+
375
+ def _join_paths(base, *parts):
376
+ """Join path parts safely."""
377
+ result = _normalize_path(base)
378
+
379
+ for part in parts:
380
+ normalized_part = _normalize_path(part)
381
+ if normalized_part.startswith("/"):
382
+ normalized_part = normalized_part[1:]
383
+
384
+ if result == "/":
385
+ result = "/" + normalized_part
386
+ else:
387
+ result = result + "/" + normalized_part
388
+
389
+ return _normalize_path(result)
390
+
391
+ def _path_to_env_var(path):
392
+ """Convert Infisical path to environment variable name."""
393
+ # Remove leading slash and replace / with _
394
+ normalized = _normalize_path(path)
395
+ if normalized.startswith("/"):
396
+ normalized = normalized[1:]
397
+
398
+ return normalized.replace("/", "_").replace("-", "_").upper()
399
+
400
+ # =============================================================================
401
+ # Service Path Registry
402
+ # =============================================================================
403
+
404
+ # Predefined service paths for known services
405
+ KNOWN_RESOURCE_PATHS = {
406
+ # Simple services
407
+ "user-management-backend": "/services/user",
408
+ "order-management-backend": "/services/order",
409
+ "order-planner-backend": "/services/order-planner",
410
+ "team-management-backend": "/services/team",
411
+ "service-management-backend": "/services/service",
412
+ "products-management-backend": "/services/products",
413
+ "website-management-backend": "/services/website",
414
+ "gdpr-compliance-backend": "/services/gdpr",
415
+
416
+ # Complex services
417
+ "payment-management-backend": "/services/payment",
418
+ "payment-processing-backend": "/services/payments",
419
+ "notification-backend": "/services/notification",
420
+
421
+ # Platform services
422
+ "api-gateway": "/services/api-gateway",
423
+ "api-gateway-test": "/services/api-gateway-test",
424
+ "orchestrator-glue-backend": "/services/orchestrator-glue",
425
+ "service-discovery-agent": "/platform/service-discovery",
426
+ "synthetic-monitor": "/platform/synthetic-monitor",
427
+
428
+ # NATS services
429
+ "nats-http-bridge": "/platform/nats-http-bridge",
430
+ "nats-http-bridge-v2": "/platform/nats-http-bridge-v2",
431
+ "nats-connector": "/platform/nats-connector",
432
+ }
433
+
434
+ def _get_known_resource_path(resource_name):
435
+ """Get predefined path for a known service."""
436
+ return KNOWN_RESOURCE_PATHS.get(resource_name)
437
+
438
+ def _register_resource_path(resource_name, path):
439
+ """Register a new service path."""
440
+ normalized = _normalize_path(path)
441
+ KNOWN_RESOURCE_PATHS[resource_name] = normalized
442
+ return normalized
443
+
444
+ # =============================================================================
445
+ # Main API
446
+ # =============================================================================
447
+
448
+ PathManager = struct(
449
+ # Path planning
450
+ plan_resource_path=_plan_resource_path,
451
+ plan_batch_resource_paths=_plan_batch_resource_paths,
452
+ plan_organization_structure=_plan_organization_structure,
453
+
454
+ # Validation
455
+ validate_path=_validate_path,
456
+ normalize_path=_normalize_path,
457
+ is_valid_path=_is_valid_path,
458
+
459
+ # Operations
460
+ get_parent_path=_get_parent_path,
461
+ get_path_depth=_get_path_depth,
462
+ join_paths=_join_paths,
463
+ path_to_env_var=_path_to_env_var,
464
+
465
+ # Registry
466
+ get_known_resource_path=_get_known_resource_path,
467
+ register_resource_path=_register_resource_path,
468
+ known_paths=KNOWN_RESOURCE_PATHS,
469
+
470
+ # Constants
471
+ ROOT_PATHS=ROOT_PATHS,
472
+ PLATFORM_PATHS=PLATFORM_PATHS,
473
+ SHARED_PATHS=SHARED_PATHS,
474
+ INFRASTRUCTURE_PATHS=INFRASTRUCTURE_PATHS,
475
+ RESOURCE_SUBPATHS=RESOURCE_SUBPATHS,
476
+ )