provisioning/core/nulib/main_provisioning/secrets.nu

83 lines
2.5 KiB
Plaintext
Raw Normal View History

# Import will be handled by parent context
feat: Complete config-driven architecture migration v2.0.0 Transform provisioning system from ENV-based to hierarchical config-driven architecture. This represents a complete system redesign with breaking changes requiring migration. ## Migration Summary - 65+ files migrated across entire codebase - 200+ ENV variables replaced with 476 config accessors - 29 syntax errors fixed across 17 files - 92% token efficiency maintained during migration ## Core Features Added ### Hierarchical Configuration System - 6-layer precedence: defaults → user → project → infra → env → runtime - Deep merge strategy with intelligent precedence rules - Multi-environment support (dev/test/prod) with auto-detection - Configuration templates for all environments ### Enhanced Interpolation Engine - Dynamic variables: {{paths.base}}, {{env.HOME}}, {{now.date}} - Git context: {{git.branch}}, {{git.commit}}, {{git.remote}} - SOPS integration: {{sops.decrypt()}} for secrets management - Path operations: {{path.join()}} for dynamic construction - Security: circular dependency detection, injection prevention ### Comprehensive Validation - Structure, path, type, semantic, and security validation - Code injection and path traversal detection - Detailed error reporting with actionable messages - Configuration health checks and warnings ## Architecture Changes ### Configuration Management (core/nulib/lib_provisioning/config/) - loader.nu: 1600+ line hierarchical config loader with validation - accessor.nu: 476 config accessor functions replacing ENV vars ### Provider System (providers/) - AWS, UpCloud, Local providers fully config-driven - Unified middleware system with standardized interfaces ### Task Services (core/nulib/taskservs/) - Kubernetes, storage, networking, registry services migrated - Template-driven configuration generation ### Cluster Management (core/nulib/clusters/) - Complete lifecycle management through configuration - Environment-specific cluster templates ## New Configuration Files - config.defaults.toml: System defaults (84 lines) - config.*.toml.example: Environment templates (400+ lines each) - Enhanced CLI: validate, env, multi-environment support ## Security Enhancements - Type-safe configuration access through validated functions - SOPS integration for encrypted secrets management - Input validation preventing injection attacks - Environment isolation and access controls ## Breaking Changes ⚠️ ENV variables no longer supported as primary configuration ⚠️ Function signatures require --config parameter ⚠️ CLI arguments and return types modified ⚠️ Provider authentication now config-driven ## Migration Path 1. Backup current environment variables 2. Copy config.user.toml.example → config.user.toml 3. Migrate ENV vars to TOML format 4. Validate: ./core/nulib/provisioning validate config 5. Test functionality with new configuration ## Validation Results ✅ Structure valid ✅ Paths valid ✅ Types valid ✅ Semantic rules valid ✅ File references valid System ready for production use with config-driven architecture. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-23 02:36:50 +00:00
use ../lib_provisioning/config/accessor.nu *
# - > Secrets management with infrastructure and services (SOPS or KMS)
export def "main secrets" [
sourcefile?: string # source file for secrets command
targetfile?: string # target file for secrets command
--provider (-p): string # secret provider: sops or kms
--encrypt (-e) # Encrypt file
--decrypt (-d) # Decrypt file
--gen (-g) # Generate encrypted files
--sed # Edit encrypted file
--debug (-x) # Use Debug mode
--xm # Debug with PROVISIONING_METADATA
--xc # Debug for task and services locally PROVISIONING_DEBUG_CHECK
--xr # Debug for remote servers PROVISIONING_DEBUG_REMOTE
--xld # Log level with DEBUG PROVISIONING_LOG_LEVEL=debug
--metadata # Error with metadata (-xm)
--notitles # not tittles
--out: string # Print Output format: json, yaml, text (default)
]: nothing -> nothing {
if ($out | is-not-empty) {
$env.PROVISIONING_OUT = $out
$env.PROVISIONING_NO_TERMINAL = true
}
# Set secret provider if specified
if ($provider | is-not-empty) {
$env.PROVISIONING_SECRET_PROVIDER = $provider
}
parse_help_command "secrets" --end
if $debug { $env.PROVISIONING_DEBUG = true }
if $sourcefile == "sed" or $sourcefile == "ed" {
on_secrets "sed" $targetfile
end_run "secrets"
return true
}
if $sed and $sourcefile != null and ($sourcefile | path exists) {
on_secrets sed $sourcefile
exit
}
if $encrypt {
if $sourcefile == null or not ($sourcefile | path exists) {
print $"🛑 Error on_secrets encrypt 'sourcefile' ($sourcefile) not found "
exit 1
}
if ($targetfile | is-not-empty) {
print $"on_secrets encrypt ($sourcefile) ($targetfile)"
on_secrets "encrypt" $sourcefile $targetfile
exit
} else {
print $"on_secrets encrypt ($sourcefile) "
print (on_secrets "encrypt" $sourcefile)
exit
}
}
if $decrypt {
if $sourcefile == null or not ($sourcefile | path exists) {
print $"🛑 Error on_secrets decrypt 'sourcefile' ($sourcefile) not found "
return false
}
if ($targetfile | is-not-empty) {
on_secrets decrypt $sourcefile $targetfile
exit
} else {
print (on_secrets decrypt $sourcefile)
exit
}
}
if $gen and $sourcefile != null {
on_secrets generate $sourcefile $targetfile
exit
}
option_undefined "secrets" ""
end_run "secrets"
}