runbooks 1.0.0__py3-none-any.whl → 1.0.2__py3-none-any.whl

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 (99) hide show
  1. runbooks/__init__.py +1 -1
  2. runbooks/cfat/WEIGHT_CONFIG_README.md +368 -0
  3. runbooks/cfat/app.ts +27 -19
  4. runbooks/cfat/assessment/runner.py +6 -5
  5. runbooks/cfat/tests/test_weight_configuration.ts +449 -0
  6. runbooks/cfat/weight_config.ts +574 -0
  7. runbooks/cloudops/models.py +20 -14
  8. runbooks/common/__init__.py +26 -9
  9. runbooks/common/aws_pricing.py +1070 -105
  10. runbooks/common/aws_pricing_api.py +276 -44
  11. runbooks/common/date_utils.py +115 -0
  12. runbooks/common/dry_run_examples.py +587 -0
  13. runbooks/common/dry_run_framework.py +520 -0
  14. runbooks/common/enhanced_exception_handler.py +10 -7
  15. runbooks/common/mcp_cost_explorer_integration.py +5 -4
  16. runbooks/common/memory_optimization.py +533 -0
  17. runbooks/common/performance_optimization_engine.py +1153 -0
  18. runbooks/common/profile_utils.py +86 -118
  19. runbooks/common/rich_utils.py +3 -3
  20. runbooks/common/sre_performance_suite.py +574 -0
  21. runbooks/finops/business_case_config.py +314 -0
  22. runbooks/finops/cost_processor.py +19 -4
  23. runbooks/finops/dashboard_runner.py +47 -28
  24. runbooks/finops/ebs_cost_optimizer.py +1 -1
  25. runbooks/finops/ebs_optimizer.py +56 -9
  26. runbooks/finops/embedded_mcp_validator.py +642 -36
  27. runbooks/finops/enhanced_trend_visualization.py +7 -2
  28. runbooks/finops/executive_export.py +789 -0
  29. runbooks/finops/finops_dashboard.py +6 -5
  30. runbooks/finops/finops_scenarios.py +34 -27
  31. runbooks/finops/iam_guidance.py +6 -1
  32. runbooks/finops/nat_gateway_optimizer.py +46 -27
  33. runbooks/finops/notebook_utils.py +1 -1
  34. runbooks/finops/schemas.py +73 -58
  35. runbooks/finops/single_dashboard.py +20 -4
  36. runbooks/finops/tests/test_integration.py +3 -1
  37. runbooks/finops/vpc_cleanup_exporter.py +2 -1
  38. runbooks/finops/vpc_cleanup_optimizer.py +22 -29
  39. runbooks/inventory/core/collector.py +51 -28
  40. runbooks/inventory/discovery.md +197 -247
  41. runbooks/inventory/inventory_modules.py +2 -2
  42. runbooks/inventory/list_ec2_instances.py +3 -3
  43. runbooks/inventory/models/account.py +5 -3
  44. runbooks/inventory/models/inventory.py +1 -1
  45. runbooks/inventory/models/resource.py +5 -3
  46. runbooks/inventory/organizations_discovery.py +102 -13
  47. runbooks/inventory/unified_validation_engine.py +2 -15
  48. runbooks/main.py +255 -92
  49. runbooks/operate/base.py +9 -6
  50. runbooks/operate/deployment_framework.py +5 -4
  51. runbooks/operate/deployment_validator.py +6 -5
  52. runbooks/operate/mcp_integration.py +6 -5
  53. runbooks/operate/networking_cost_heatmap.py +17 -13
  54. runbooks/operate/vpc_operations.py +82 -13
  55. runbooks/remediation/base.py +3 -1
  56. runbooks/remediation/commons.py +5 -5
  57. runbooks/remediation/commvault_ec2_analysis.py +66 -18
  58. runbooks/remediation/config/accounts_example.json +31 -0
  59. runbooks/remediation/multi_account.py +120 -7
  60. runbooks/remediation/remediation_cli.py +710 -0
  61. runbooks/remediation/universal_account_discovery.py +377 -0
  62. runbooks/remediation/workspaces_list.py +2 -2
  63. runbooks/security/compliance_automation_engine.py +99 -20
  64. runbooks/security/config/__init__.py +24 -0
  65. runbooks/security/config/compliance_config.py +255 -0
  66. runbooks/security/config/compliance_weights_example.json +22 -0
  67. runbooks/security/config_template_generator.py +500 -0
  68. runbooks/security/security_cli.py +377 -0
  69. runbooks/validation/cli.py +8 -7
  70. runbooks/validation/comprehensive_2way_validator.py +26 -15
  71. runbooks/validation/mcp_validator.py +62 -8
  72. runbooks/vpc/config.py +49 -15
  73. runbooks/vpc/cross_account_session.py +5 -1
  74. runbooks/vpc/heatmap_engine.py +438 -59
  75. runbooks/vpc/mcp_no_eni_validator.py +115 -36
  76. runbooks/vpc/performance_optimized_analyzer.py +546 -0
  77. runbooks/vpc/runbooks_adapter.py +33 -12
  78. runbooks/vpc/tests/conftest.py +4 -2
  79. runbooks/vpc/tests/test_cost_engine.py +3 -1
  80. {runbooks-1.0.0.dist-info → runbooks-1.0.2.dist-info}/METADATA +1 -1
  81. {runbooks-1.0.0.dist-info → runbooks-1.0.2.dist-info}/RECORD +85 -79
  82. runbooks/finops/runbooks.inventory.organizations_discovery.log +0 -0
  83. runbooks/finops/runbooks.security.report_generator.log +0 -0
  84. runbooks/finops/runbooks.security.run_script.log +0 -0
  85. runbooks/finops/runbooks.security.security_export.log +0 -0
  86. runbooks/finops/tests/results_test_finops_dashboard.xml +0 -1
  87. runbooks/inventory/artifacts/scale-optimize-status.txt +0 -12
  88. runbooks/inventory/runbooks.inventory.organizations_discovery.log +0 -0
  89. runbooks/inventory/runbooks.security.report_generator.log +0 -0
  90. runbooks/inventory/runbooks.security.run_script.log +0 -0
  91. runbooks/inventory/runbooks.security.security_export.log +0 -0
  92. runbooks/vpc/runbooks.inventory.organizations_discovery.log +0 -0
  93. runbooks/vpc/runbooks.security.report_generator.log +0 -0
  94. runbooks/vpc/runbooks.security.run_script.log +0 -0
  95. runbooks/vpc/runbooks.security.security_export.log +0 -0
  96. {runbooks-1.0.0.dist-info → runbooks-1.0.2.dist-info}/WHEEL +0 -0
  97. {runbooks-1.0.0.dist-info → runbooks-1.0.2.dist-info}/entry_points.txt +0 -0
  98. {runbooks-1.0.0.dist-info → runbooks-1.0.2.dist-info}/licenses/LICENSE +0 -0
  99. {runbooks-1.0.0.dist-info → runbooks-1.0.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,574 @@
1
+ /**
2
+ * Dynamic Weight Configuration System for CFAT Assessment
3
+ *
4
+ * Replaces 30+ hardcoded weight values with flexible, environment-aware
5
+ * configuration system supporting multiple compliance frameworks.
6
+ *
7
+ * Enterprise Features:
8
+ * - Framework-specific weight profiles (AWS Well-Architected, SOC2, etc.)
9
+ * - Environment-based weight adjustments (dev, staging, prod)
10
+ * - Dynamic weight calculation based on organization size
11
+ * - Override capabilities for specific requirements
12
+ */
13
+
14
+ export interface WeightConfig {
15
+ // Core organizational checks
16
+ organization_created: number;
17
+ management_account_created: number;
18
+
19
+ // Identity and access management
20
+ iam_users_removed: number;
21
+ iam_idc_org_service_enabled: number;
22
+ iam_idc_configured: number;
23
+
24
+ // Resource management (Security best practices)
25
+ ec2_instances_removed: number;
26
+ vpc_removed: number;
27
+
28
+ // Logging and monitoring (Critical for compliance)
29
+ cloudtrail_created: number;
30
+ cloudtrail_org_service_enabled: number;
31
+ cloudtrail_org_trail_deployed: number;
32
+ config_recorder_management: number;
33
+ config_delivery_channel_management: number;
34
+
35
+ // Service integrations (Operational excellence)
36
+ cloudformation_stacksets_activated: number;
37
+ cloudformation_org_service_enabled: number;
38
+ guardduty_org_service_enabled: number;
39
+ ram_org_service_enabled: number;
40
+ securityhub_org_service_enabled: number;
41
+ iam_access_analyzer_org_service_enabled: number;
42
+ config_org_service_enabled: number;
43
+ backup_org_service_enabled: number;
44
+
45
+ // Organizational structure
46
+ infrastructure_ou_deployed: number;
47
+ security_ou_deployed: number;
48
+ workloads_ou_deployed: number;
49
+
50
+ // Governance and policies
51
+ scp_enabled: number;
52
+ tag_policy_enabled: number;
53
+ backup_policy_enabled: number;
54
+
55
+ // Control Tower (Landing Zone foundation)
56
+ control_tower_deployed: number;
57
+ control_tower_latest_version: number;
58
+ control_tower_not_drifted: number;
59
+
60
+ // Core accounts
61
+ log_archive_account_deployed: number;
62
+ audit_account_deployed: number;
63
+
64
+ // Legacy compliance
65
+ legacy_cur_setup: number;
66
+ }
67
+
68
+ export enum ComplianceFramework {
69
+ AWS_WELL_ARCHITECTED = 'aws-well-architected',
70
+ SOC2 = 'soc2',
71
+ PCI_DSS = 'pci-dss',
72
+ HIPAA = 'hipaa',
73
+ NIST = 'nist',
74
+ ISO_27001 = 'iso-27001',
75
+ CIS_BENCHMARKS = 'cis',
76
+ CUSTOM = 'custom'
77
+ }
78
+
79
+ export enum EnvironmentType {
80
+ DEVELOPMENT = 'development',
81
+ STAGING = 'staging',
82
+ PRODUCTION = 'production',
83
+ SANDBOX = 'sandbox'
84
+ }
85
+
86
+ export enum OrganizationSize {
87
+ SMALL = 'small', // < 10 accounts
88
+ MEDIUM = 'medium', // 10-100 accounts
89
+ LARGE = 'large', // 100-1000 accounts
90
+ ENTERPRISE = 'enterprise' // > 1000 accounts
91
+ }
92
+
93
+ /**
94
+ * Default weight configurations for different compliance frameworks
95
+ */
96
+ export const FRAMEWORK_WEIGHTS: Record<ComplianceFramework, WeightConfig> = {
97
+ [ComplianceFramework.AWS_WELL_ARCHITECTED]: {
98
+ // Foundational requirements (Critical - Weight 6)
99
+ organization_created: 6,
100
+ management_account_created: 6,
101
+ cloudtrail_created: 6,
102
+ cloudtrail_org_service_enabled: 6,
103
+ cloudtrail_org_trail_deployed: 6,
104
+ config_recorder_management: 6,
105
+ config_delivery_channel_management: 6,
106
+ iam_idc_org_service_enabled: 6,
107
+ iam_idc_configured: 6,
108
+ scp_enabled: 6,
109
+ tag_policy_enabled: 6,
110
+ control_tower_deployed: 6,
111
+ control_tower_not_drifted: 6,
112
+ security_ou_deployed: 6,
113
+ log_archive_account_deployed: 6,
114
+ audit_account_deployed: 6,
115
+
116
+ // Important but not critical (Weight 5)
117
+ cloudformation_stacksets_activated: 5,
118
+ cloudformation_org_service_enabled: 5,
119
+ infrastructure_ou_deployed: 5,
120
+ workloads_ou_deployed: 5,
121
+ backup_policy_enabled: 5,
122
+ control_tower_latest_version: 5,
123
+
124
+ // Best practices (Weight 4)
125
+ iam_users_removed: 4,
126
+ ec2_instances_removed: 4,
127
+ vpc_removed: 4,
128
+ legacy_cur_setup: 4,
129
+ guardduty_org_service_enabled: 4,
130
+ ram_org_service_enabled: 4,
131
+ securityhub_org_service_enabled: 4,
132
+ iam_access_analyzer_org_service_enabled: 4,
133
+ config_org_service_enabled: 4,
134
+ backup_org_service_enabled: 4
135
+ },
136
+
137
+ [ComplianceFramework.SOC2]: {
138
+ // SOC2 emphasizes security and availability (Higher security weights)
139
+ organization_created: 6,
140
+ management_account_created: 6,
141
+ cloudtrail_created: 6,
142
+ cloudtrail_org_service_enabled: 6,
143
+ cloudtrail_org_trail_deployed: 6,
144
+ config_recorder_management: 6,
145
+ config_delivery_channel_management: 6,
146
+ iam_idc_org_service_enabled: 6,
147
+ iam_idc_configured: 6,
148
+ scp_enabled: 6,
149
+ tag_policy_enabled: 5,
150
+ control_tower_deployed: 6,
151
+ control_tower_not_drifted: 6,
152
+ security_ou_deployed: 6,
153
+ log_archive_account_deployed: 6,
154
+ audit_account_deployed: 6,
155
+ securityhub_org_service_enabled: 6, // Higher weight for SOC2
156
+ iam_access_analyzer_org_service_enabled: 6, // Higher weight for SOC2
157
+
158
+ // Enhanced security monitoring
159
+ cloudformation_stacksets_activated: 5,
160
+ cloudformation_org_service_enabled: 5,
161
+ infrastructure_ou_deployed: 5,
162
+ workloads_ou_deployed: 5,
163
+ backup_policy_enabled: 6, // Higher for data protection
164
+ control_tower_latest_version: 5,
165
+ guardduty_org_service_enabled: 6, // Higher for threat detection
166
+
167
+ // Management account hygiene (Important for SOC2)
168
+ iam_users_removed: 5, // Higher weight for SOC2
169
+ ec2_instances_removed: 5, // Higher weight for SOC2
170
+ vpc_removed: 5, // Higher weight for SOC2
171
+ legacy_cur_setup: 4,
172
+ ram_org_service_enabled: 4,
173
+ config_org_service_enabled: 5,
174
+ backup_org_service_enabled: 6
175
+ },
176
+
177
+ [ComplianceFramework.PCI_DSS]: {
178
+ // PCI-DSS focuses on data protection and network security
179
+ organization_created: 6,
180
+ management_account_created: 6,
181
+ cloudtrail_created: 6,
182
+ cloudtrail_org_service_enabled: 6,
183
+ cloudtrail_org_trail_deployed: 6,
184
+ config_recorder_management: 6,
185
+ config_delivery_channel_management: 6,
186
+ iam_idc_org_service_enabled: 6,
187
+ iam_idc_configured: 6,
188
+ scp_enabled: 6,
189
+ tag_policy_enabled: 6,
190
+ control_tower_deployed: 6,
191
+ control_tower_not_drifted: 6,
192
+ security_ou_deployed: 6,
193
+ log_archive_account_deployed: 6,
194
+ audit_account_deployed: 6,
195
+
196
+ // Enhanced for PCI-DSS network and data requirements
197
+ securityhub_org_service_enabled: 6,
198
+ iam_access_analyzer_org_service_enabled: 6,
199
+ guardduty_org_service_enabled: 6,
200
+ backup_policy_enabled: 6,
201
+ backup_org_service_enabled: 6,
202
+
203
+ // Network isolation requirements
204
+ iam_users_removed: 6, // Critical for PCI-DSS
205
+ ec2_instances_removed: 6, // Critical for network isolation
206
+ vpc_removed: 6, // Critical for network isolation
207
+
208
+ cloudformation_stacksets_activated: 5,
209
+ cloudformation_org_service_enabled: 5,
210
+ infrastructure_ou_deployed: 5,
211
+ workloads_ou_deployed: 5,
212
+ control_tower_latest_version: 5,
213
+ legacy_cur_setup: 4,
214
+ ram_org_service_enabled: 4,
215
+ config_org_service_enabled: 5
216
+ },
217
+
218
+ [ComplianceFramework.HIPAA]: {
219
+ // HIPAA emphasizes data protection and audit trails
220
+ organization_created: 6,
221
+ management_account_created: 6,
222
+ cloudtrail_created: 6,
223
+ cloudtrail_org_service_enabled: 6,
224
+ cloudtrail_org_trail_deployed: 6,
225
+ config_recorder_management: 6,
226
+ config_delivery_channel_management: 6,
227
+ iam_idc_org_service_enabled: 6,
228
+ iam_idc_configured: 6,
229
+ scp_enabled: 6,
230
+ tag_policy_enabled: 6,
231
+ control_tower_deployed: 6,
232
+ control_tower_not_drifted: 6,
233
+ security_ou_deployed: 6,
234
+ log_archive_account_deployed: 6,
235
+ audit_account_deployed: 6,
236
+
237
+ // Data protection and monitoring
238
+ securityhub_org_service_enabled: 6,
239
+ iam_access_analyzer_org_service_enabled: 6,
240
+ backup_policy_enabled: 6,
241
+ backup_org_service_enabled: 6,
242
+ config_org_service_enabled: 6,
243
+
244
+ // Audit and compliance
245
+ cloudformation_stacksets_activated: 5,
246
+ cloudformation_org_service_enabled: 5,
247
+ infrastructure_ou_deployed: 5,
248
+ workloads_ou_deployed: 5,
249
+ control_tower_latest_version: 5,
250
+ guardduty_org_service_enabled: 5,
251
+
252
+ // Access controls
253
+ iam_users_removed: 5,
254
+ ec2_instances_removed: 4,
255
+ vpc_removed: 4,
256
+ legacy_cur_setup: 4,
257
+ ram_org_service_enabled: 4
258
+ },
259
+
260
+ [ComplianceFramework.NIST]: {
261
+ // NIST Cybersecurity Framework alignment
262
+ organization_created: 6,
263
+ management_account_created: 6,
264
+ cloudtrail_created: 6,
265
+ cloudtrail_org_service_enabled: 6,
266
+ cloudtrail_org_trail_deployed: 6,
267
+ config_recorder_management: 6,
268
+ config_delivery_channel_management: 6,
269
+ iam_idc_org_service_enabled: 6,
270
+ iam_idc_configured: 6,
271
+ scp_enabled: 6,
272
+ tag_policy_enabled: 5,
273
+ control_tower_deployed: 6,
274
+ control_tower_not_drifted: 6,
275
+ security_ou_deployed: 6,
276
+ log_archive_account_deployed: 6,
277
+ audit_account_deployed: 6,
278
+
279
+ // Identify, Protect, Detect framework
280
+ securityhub_org_service_enabled: 6,
281
+ iam_access_analyzer_org_service_enabled: 6,
282
+ guardduty_org_service_enabled: 6,
283
+ backup_policy_enabled: 5,
284
+ backup_org_service_enabled: 5,
285
+
286
+ cloudformation_stacksets_activated: 5,
287
+ cloudformation_org_service_enabled: 5,
288
+ infrastructure_ou_deployed: 5,
289
+ workloads_ou_deployed: 5,
290
+ control_tower_latest_version: 5,
291
+ config_org_service_enabled: 5,
292
+
293
+ iam_users_removed: 4,
294
+ ec2_instances_removed: 4,
295
+ vpc_removed: 4,
296
+ legacy_cur_setup: 4,
297
+ ram_org_service_enabled: 4
298
+ },
299
+
300
+ [ComplianceFramework.ISO_27001]: {
301
+ // ISO 27001 Information Security Management
302
+ organization_created: 6,
303
+ management_account_created: 6,
304
+ cloudtrail_created: 6,
305
+ cloudtrail_org_service_enabled: 6,
306
+ cloudtrail_org_trail_deployed: 6,
307
+ config_recorder_management: 6,
308
+ config_delivery_channel_management: 6,
309
+ iam_idc_org_service_enabled: 6,
310
+ iam_idc_configured: 6,
311
+ scp_enabled: 6,
312
+ tag_policy_enabled: 6,
313
+ control_tower_deployed: 6,
314
+ control_tower_not_drifted: 6,
315
+ security_ou_deployed: 6,
316
+ log_archive_account_deployed: 6,
317
+ audit_account_deployed: 6,
318
+
319
+ // Information security controls
320
+ securityhub_org_service_enabled: 6,
321
+ iam_access_analyzer_org_service_enabled: 6,
322
+ backup_policy_enabled: 6,
323
+ backup_org_service_enabled: 6,
324
+ config_org_service_enabled: 6,
325
+ guardduty_org_service_enabled: 5,
326
+
327
+ cloudformation_stacksets_activated: 5,
328
+ cloudformation_org_service_enabled: 5,
329
+ infrastructure_ou_deployed: 5,
330
+ workloads_ou_deployed: 5,
331
+ control_tower_latest_version: 5,
332
+
333
+ iam_users_removed: 5,
334
+ ec2_instances_removed: 4,
335
+ vpc_removed: 4,
336
+ legacy_cur_setup: 4,
337
+ ram_org_service_enabled: 4
338
+ },
339
+
340
+ [ComplianceFramework.CIS_BENCHMARKS]: {
341
+ // CIS Controls alignment
342
+ organization_created: 6,
343
+ management_account_created: 6,
344
+ cloudtrail_created: 6,
345
+ cloudtrail_org_service_enabled: 6,
346
+ cloudtrail_org_trail_deployed: 6,
347
+ config_recorder_management: 6,
348
+ config_delivery_channel_management: 6,
349
+ iam_idc_org_service_enabled: 6,
350
+ iam_idc_configured: 6,
351
+ scp_enabled: 6,
352
+ tag_policy_enabled: 5,
353
+ control_tower_deployed: 6,
354
+ control_tower_not_drifted: 6,
355
+ security_ou_deployed: 6,
356
+ log_archive_account_deployed: 6,
357
+ audit_account_deployed: 6,
358
+
359
+ // CIS Controls emphasis
360
+ securityhub_org_service_enabled: 6,
361
+ iam_access_analyzer_org_service_enabled: 6,
362
+ guardduty_org_service_enabled: 6,
363
+ backup_policy_enabled: 5,
364
+ backup_org_service_enabled: 5,
365
+ config_org_service_enabled: 6,
366
+
367
+ cloudformation_stacksets_activated: 5,
368
+ cloudformation_org_service_enabled: 5,
369
+ infrastructure_ou_deployed: 5,
370
+ workloads_ou_deployed: 5,
371
+ control_tower_latest_version: 5,
372
+
373
+ // Asset and access management
374
+ iam_users_removed: 5,
375
+ ec2_instances_removed: 5,
376
+ vpc_removed: 5,
377
+ legacy_cur_setup: 4,
378
+ ram_org_service_enabled: 4
379
+ },
380
+
381
+ [ComplianceFramework.CUSTOM]: {
382
+ // Balanced default weights (original hardcoded values preserved)
383
+ organization_created: 6,
384
+ management_account_created: 6,
385
+ iam_users_removed: 4,
386
+ ec2_instances_removed: 4,
387
+ vpc_removed: 4,
388
+ legacy_cur_setup: 4,
389
+ cloudtrail_created: 6,
390
+ cloudtrail_org_service_enabled: 6,
391
+ cloudtrail_org_trail_deployed: 6,
392
+ config_recorder_management: 6,
393
+ config_delivery_channel_management: 6,
394
+ cloudformation_stacksets_activated: 5,
395
+ guardduty_org_service_enabled: 4,
396
+ ram_org_service_enabled: 4,
397
+ securityhub_org_service_enabled: 4,
398
+ iam_access_analyzer_org_service_enabled: 4,
399
+ config_org_service_enabled: 4,
400
+ cloudformation_org_service_enabled: 5,
401
+ backup_org_service_enabled: 4,
402
+ infrastructure_ou_deployed: 5,
403
+ security_ou_deployed: 6,
404
+ workloads_ou_deployed: 5,
405
+ iam_idc_org_service_enabled: 6,
406
+ iam_idc_configured: 6,
407
+ scp_enabled: 6,
408
+ tag_policy_enabled: 6,
409
+ backup_policy_enabled: 5,
410
+ control_tower_deployed: 6,
411
+ control_tower_latest_version: 5,
412
+ control_tower_not_drifted: 6,
413
+ log_archive_account_deployed: 6,
414
+ audit_account_deployed: 6
415
+ }
416
+ };
417
+
418
+ /**
419
+ * Environment-based weight modifiers
420
+ */
421
+ export const ENVIRONMENT_MODIFIERS: Record<EnvironmentType, number> = {
422
+ [EnvironmentType.DEVELOPMENT]: 0.8, // 20% reduction for dev environments
423
+ [EnvironmentType.STAGING]: 0.9, // 10% reduction for staging
424
+ [EnvironmentType.PRODUCTION]: 1.0, // Full weight for production
425
+ [EnvironmentType.SANDBOX]: 0.6 // 40% reduction for sandbox
426
+ };
427
+
428
+ /**
429
+ * Organization size-based weight adjustments
430
+ */
431
+ export const SIZE_MODIFIERS: Record<OrganizationSize, Partial<WeightConfig>> = {
432
+ [OrganizationSize.SMALL]: {
433
+ // Small orgs might not need all enterprise features
434
+ infrastructure_ou_deployed: -1,
435
+ workloads_ou_deployed: -1,
436
+ backup_policy_enabled: -1
437
+ },
438
+ [OrganizationSize.MEDIUM]: {
439
+ // Medium orgs benefit from all features
440
+ },
441
+ [OrganizationSize.LARGE]: {
442
+ // Large orgs need enhanced governance
443
+ scp_enabled: +1,
444
+ tag_policy_enabled: +1,
445
+ backup_policy_enabled: +1
446
+ },
447
+ [OrganizationSize.ENTERPRISE]: {
448
+ // Enterprise requires maximum governance
449
+ scp_enabled: +1,
450
+ tag_policy_enabled: +1,
451
+ backup_policy_enabled: +1,
452
+ control_tower_deployed: +1,
453
+ security_ou_deployed: +1
454
+ }
455
+ };
456
+
457
+ /**
458
+ * Get dynamic weight configuration based on environment context
459
+ */
460
+ export function getWeightConfig(
461
+ framework: ComplianceFramework = ComplianceFramework.AWS_WELL_ARCHITECTED,
462
+ environment: EnvironmentType = EnvironmentType.PRODUCTION,
463
+ orgSize: OrganizationSize = OrganizationSize.MEDIUM,
464
+ customOverrides: Partial<WeightConfig> = {}
465
+ ): WeightConfig {
466
+ // Start with framework-specific weights
467
+ const baseWeights = { ...FRAMEWORK_WEIGHTS[framework] };
468
+
469
+ // Apply environment modifier
470
+ const envModifier = ENVIRONMENT_MODIFIERS[environment];
471
+
472
+ // Apply size-based adjustments
473
+ const sizeAdjustments = SIZE_MODIFIERS[orgSize] || {};
474
+
475
+ // Calculate final weights
476
+ const finalWeights: WeightConfig = { ...baseWeights };
477
+
478
+ // Apply environment modifier (multiply by modifier, round to nearest integer)
479
+ Object.keys(finalWeights).forEach(key => {
480
+ const typedKey = key as keyof WeightConfig;
481
+ finalWeights[typedKey] = Math.round(baseWeights[typedKey] * envModifier);
482
+ });
483
+
484
+ // Apply size adjustments (add/subtract values)
485
+ Object.keys(sizeAdjustments).forEach(key => {
486
+ const typedKey = key as keyof WeightConfig;
487
+ if (finalWeights[typedKey] !== undefined && sizeAdjustments[typedKey] !== undefined) {
488
+ finalWeights[typedKey] = Math.max(1, finalWeights[typedKey] + sizeAdjustments[typedKey]!);
489
+ }
490
+ });
491
+
492
+ // Apply custom overrides
493
+ Object.keys(customOverrides).forEach(key => {
494
+ const typedKey = key as keyof WeightConfig;
495
+ if (customOverrides[typedKey] !== undefined) {
496
+ finalWeights[typedKey] = customOverrides[typedKey]!;
497
+ }
498
+ });
499
+
500
+ return finalWeights;
501
+ }
502
+
503
+ /**
504
+ * Validate weight configuration values
505
+ */
506
+ export function validateWeightConfig(config: WeightConfig): { valid: boolean; errors: string[] } {
507
+ const errors: string[] = [];
508
+
509
+ Object.entries(config).forEach(([key, value]) => {
510
+ if (typeof value !== 'number') {
511
+ errors.push(`Weight for ${key} must be a number, got ${typeof value}`);
512
+ } else if (value < 1 || value > 10) {
513
+ errors.push(`Weight for ${key} must be between 1 and 10, got ${value}`);
514
+ } else if (!Number.isInteger(value)) {
515
+ errors.push(`Weight for ${key} must be an integer, got ${value}`);
516
+ }
517
+ });
518
+
519
+ return {
520
+ valid: errors.length === 0,
521
+ errors
522
+ };
523
+ }
524
+
525
+ /**
526
+ * Load weight configuration from environment variables or defaults
527
+ */
528
+ export function loadWeightConfigFromEnv(): {
529
+ framework: ComplianceFramework;
530
+ environment: EnvironmentType;
531
+ orgSize: OrganizationSize;
532
+ customOverrides: Partial<WeightConfig>;
533
+ } {
534
+ // Load from environment variables with sensible defaults
535
+ const framework = (process.env.CFAT_COMPLIANCE_FRAMEWORK as ComplianceFramework)
536
+ || ComplianceFramework.AWS_WELL_ARCHITECTED;
537
+
538
+ const environment = (process.env.CFAT_ENVIRONMENT_TYPE as EnvironmentType)
539
+ || EnvironmentType.PRODUCTION;
540
+
541
+ const orgSize = (process.env.CFAT_ORG_SIZE as OrganizationSize)
542
+ || OrganizationSize.MEDIUM;
543
+
544
+ // Load custom overrides from environment (JSON format)
545
+ let customOverrides: Partial<WeightConfig> = {};
546
+ const customOverridesEnv = process.env.CFAT_WEIGHT_OVERRIDES;
547
+ if (customOverridesEnv) {
548
+ try {
549
+ customOverrides = JSON.parse(customOverridesEnv);
550
+ } catch (error) {
551
+ console.warn('Invalid JSON in CFAT_WEIGHT_OVERRIDES, using defaults:', error);
552
+ }
553
+ }
554
+
555
+ return {
556
+ framework,
557
+ environment,
558
+ orgSize,
559
+ customOverrides
560
+ };
561
+ }
562
+
563
+ /**
564
+ * Export default configuration for easy importing
565
+ */
566
+ export function getDefaultWeightConfig(): WeightConfig {
567
+ const envConfig = loadWeightConfigFromEnv();
568
+ return getWeightConfig(
569
+ envConfig.framework,
570
+ envConfig.environment,
571
+ envConfig.orgSize,
572
+ envConfig.customOverrides
573
+ );
574
+ }
@@ -10,7 +10,7 @@ Strategic Alignment:
10
10
  - Integration with Rich CLI for consistent UX
11
11
  """
12
12
 
13
- from pydantic import BaseModel, Field, validator, root_validator
13
+ from pydantic import BaseModel, Field, field_validator
14
14
  from typing import List, Dict, Optional, Union, Any
15
15
  from enum import Enum
16
16
  from datetime import datetime
@@ -58,7 +58,8 @@ class ResourceImpact(BaseModel):
58
58
  modification_required: bool = Field(description="Whether resource requires modification", default=False)
59
59
  estimated_downtime: Optional[float] = Field(description="Expected downtime in minutes", default=None)
60
60
 
61
- @validator('risk_level')
61
+ @field_validator('risk_level')
62
+ @classmethod
62
63
  def validate_risk_level(cls, v):
63
64
  """Ensure risk level is valid."""
64
65
  if isinstance(v, str):
@@ -68,11 +69,12 @@ class ResourceImpact(BaseModel):
68
69
  raise ValueError(f'Risk level must be one of: {[e.value for e in RiskLevel]}')
69
70
  return v
70
71
 
71
- @validator('projected_savings')
72
- def validate_savings(cls, v, values):
72
+ @field_validator('projected_savings')
73
+ @classmethod
74
+ def validate_savings(cls, v, info):
73
75
  """Validate savings against current cost."""
74
- if v is not None and 'estimated_monthly_cost' in values:
75
- current_cost = values['estimated_monthly_cost']
76
+ if v is not None and 'estimated_monthly_cost' in info.data:
77
+ current_cost = info.data['estimated_monthly_cost']
76
78
  if current_cost is not None and v > current_cost:
77
79
  raise ValueError('Projected savings cannot exceed current cost')
78
80
  return v
@@ -85,10 +87,11 @@ class ComplianceMetrics(BaseModel):
85
87
  violations_found: int = Field(ge=0, description="Number of violations identified")
86
88
  violations_fixed: int = Field(ge=0, description="Number of violations remediated")
87
89
 
88
- @validator('violations_fixed')
89
- def validate_violations_fixed(cls, v, values):
90
+ @field_validator('violations_fixed')
91
+ @classmethod
92
+ def validate_violations_fixed(cls, v, info):
90
93
  """Ensure violations fixed doesn't exceed violations found."""
91
- if 'violations_found' in values and v > values['violations_found']:
94
+ if 'violations_found' in info.data and v > info.data['violations_found']:
92
95
  raise ValueError('Violations fixed cannot exceed violations found')
93
96
  return v
94
97
 
@@ -137,7 +140,8 @@ class CloudOpsExecutionResult(BaseModel):
137
140
  regions_analyzed: List[str] = Field(description="AWS regions analyzed", default=[])
138
141
  services_analyzed: List[str] = Field(description="AWS services analyzed", default=[])
139
142
 
140
- @validator('execution_time')
143
+ @field_validator('execution_time')
144
+ @classmethod
141
145
  def validate_execution_time(cls, v):
142
146
  """Ensure execution time is positive."""
143
147
  if v < 0:
@@ -171,10 +175,11 @@ class CostOptimizationResult(CloudOpsExecutionResult):
171
175
  oversized_resources: List[ResourceImpact] = Field(description="Identified oversized resources", default=[])
172
176
  unattached_resources: List[ResourceImpact] = Field(description="Identified unattached resources", default=[])
173
177
 
174
- @validator('optimized_monthly_spend')
175
- def validate_optimized_spend(cls, v, values):
178
+ @field_validator('optimized_monthly_spend')
179
+ @classmethod
180
+ def validate_optimized_spend(cls, v, info):
176
181
  """Ensure optimized spend is less than current spend."""
177
- if 'current_monthly_spend' in values and v > values['current_monthly_spend']:
182
+ if 'current_monthly_spend' in info.data and v > info.data['current_monthly_spend']:
178
183
  raise ValueError('Optimized spend cannot exceed current spend')
179
184
  return v
180
185
 
@@ -205,7 +210,8 @@ class ProfileConfiguration(BaseModel):
205
210
  account_id: Optional[str] = Field(description="AWS account ID")
206
211
  regions: List[str] = Field(description="Target AWS regions", default=["us-east-1"])
207
212
 
208
- @validator('profile_name')
213
+ @field_validator('profile_name')
214
+ @classmethod
209
215
  def validate_profile_exists(cls, v):
210
216
  """Validate that AWS profile exists in local configuration."""
211
217
  try: