refactor: migrate business logic from cmd/ to pkg/ (DRY architecture)#43
Merged
CodeMonkeyCybersecurity merged 1 commit intomainfrom Nov 8, 2025
Conversation
PATTERN COMPLIANCE (P0 - CRITICAL): - Enforces CLAUDE.md architecture: cmd/ = orchestration, pkg/ = business logic - Reduces cmd/ file sizes to meet <100 lines guideline - Follows Assess → Intervene → Evaluate pattern in migrated code - Uses structured logging (otelzap.Ctx) exclusively MIGRATIONS COMPLETED: 1. cmd/backup/restore-hecate.go → pkg/backup/restore_hecate.go - Migrated: AutoRestore(), InteractiveRestore(), RestoreResource() - REDUCTION: 118 lines → 32 lines (73% reduction) - PATTERN: All functions follow A→I→E pattern with structured logging - cmd/ now contains ONLY Cobra orchestration 2. cmd/update/ldap.go → pkg/ldap/certificate.go - Migrated: RegenerateTLSCertificate(), ValidateIPAddress() - REDUCTION: 88 lines → 46 lines (48% reduction) - SECURITY: Centralized IP validation prevents command injection - SECURITY: Added comprehensive threat model documentation - cmd/ now delegates to pkg/ldap with config struct 3. cmd/create/hecate_dns.go → pkg/shared/helpers.go - Migrated: getEnvOrDefault() → GetEnvOrDefault() - BENEFIT: Shared utility now available across entire codebase - UPDATED: All 5 usages in hecate_dns.go to use shared function NEW FILES CREATED: - pkg/backup/restore_hecate.go (210 lines) - Hecate backup/restore logic - pkg/ldap/certificate.go (138 lines) - LDAP certificate management FILES MODIFIED: - cmd/backup/restore-hecate.go - Now pure orchestration (32 lines) - cmd/update/ldap.go - Now pure orchestration (46 lines) - cmd/create/hecate_dns.go - Uses shared.GetEnvOrDefault - pkg/shared/helpers.go - Added GetEnvOrDefault utility SECURITY IMPROVEMENTS: - Centralized IP validation with explicit threat model (ldap/certificate.go:40-47) - Command injection prevention documented (SECURITY comments) - CVSS threat scenarios documented in code BENEFITS: - Improved testability: Business logic isolated in pkg/ for unit testing - Better reusability: Functions now available across codebase - Clearer separation: cmd/ files now <100 lines, easy to understand - Maintainability: Single responsibility - cmd/ does CLI, pkg/ does work - Documentation: All pkg/ functions have A→I→E structure documented RELATED ISSUES: Addresses technical debt from ROADMAP.md VERIFICATION: gofmt -l passed, all files properly formatted
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PATTERN COMPLIANCE (P0 - CRITICAL):
MIGRATIONS COMPLETED:
cmd/backup/restore-hecate.go → pkg/backup/restore_hecate.go
cmd/update/ldap.go → pkg/ldap/certificate.go
cmd/create/hecate_dns.go → pkg/shared/helpers.go
NEW FILES CREATED:
FILES MODIFIED:
SECURITY IMPROVEMENTS:
BENEFITS:
RELATED ISSUES: Addresses technical debt from ROADMAP.md
VERIFICATION: gofmt -l passed, all files properly formatted