Skip to content

Refactoring externalcas plugin to improve readability and testability - #8

Merged
netops2devops merged 3 commits into
mainfrom
develop/refactor
Jan 27, 2026
Merged

netops2devops merged 3 commits into
mainfrom
develop/refactor

Conversation

@netops2devops

Copy link
Copy Markdown
Contributor

refactor(externalcas): enhance testability and fix config parsing

  • Fix duplicate config parsing bug by caching parsed configuration
  • Extract validation functions for independent testing
  • Add ACMEClient interface for dependency injection and mocking
  • Make SplitCertificateBundle public
  • Add comprehensive unit tests with mock ACME client
  • Maintain backward compatibility with apiv1 interface

I used Claude Code to assist me with refactoring although I manually reviewed & tested all the proposed changes.

Refactor the externalcas package to enhance code quality through better
separation of concerns and improved testability while preserving all
existing functionality.

Changes:
- Config caching: Parse and validate AcmeProxyConfig once instead of twice
  per request (eliminated duplicate unmarshaling bug)
- Add config validation with Validate() method and timeout helpers
  (HTTPTimeout, RequestTimeout)
- Extract validation functions: ValidateCreateCertificateRequest and
  ValidateRevokeCertificateRequest for independent testing
- Make SplitCertificateBundle public to enable reuse and direct testing
- Introduce ACMEClient interface with legoClientAdapter for dependency
  injection and mock-based testing
- Add comprehensive unit tests for validation, config, and certificate
  processing with mock ACME client

Benefits:
- Config parsed once and cached (performance + bug fix)
- All validation logic independently testable
- Certificate processing testable without network calls
- No breaking changes to public API or apiv1 interface
- Plugin registration pattern preserved
@netops2devops
netops2devops merged commit c3bde8f into main Jan 27, 2026
7 checks passed
@netops2devops
netops2devops deleted the develop/refactor branch January 27, 2026 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant