Skip to content

refactor(api): extract certificate normalization from AddCertificate - #1333

Merged
rsdmike merged 1 commit into
mainfrom
refactor/add-certificate-complexity
Oct 16, 2026
Merged

rsdmike merged 1 commit into
mainfrom
refactor/add-certificate-complexity

Conversation

@rsdmike

@rsdmike rsdmike commented Oct 16, 2026

Copy link
Copy Markdown
Member

CI installs the latest golangci-lint. v2.15.0 reports AddCertificate at cognitive complexity 17 (limit 16), which fails the golangci-lint job on every PR.

This moves the base64/PEM decode, parse, and expiry checks into normalizeCertificate with no behavior change. golangci-lint v2.15.0 reports 0 issues.

@rsdmike
rsdmike requested a review from a team as a code owner October 16, 2026 22:02
Copilot AI balanced review requested due to automatic review settings October 16, 2026 22:02
@rsdmike
rsdmike force-pushed the refactor/add-certificate-complexity branch from dc27b60 to 4de2317 Compare October 16, 2026 22:03
@rsdmike
rsdmike enabled auto-merge (squash) October 16, 2026 22:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Empty normalization results now reach device operations instead of returning early, violating the intended behavior preservation.

1 open issue
What changed in this PR

Extracts certificate normalization into a helper to reduce AddCertificate complexity and resolve the reported lint failure.

Changes:

  • Moves decoding, parsing, and expiry checks into normalizeCertificate.
  • Calls the helper before setting up the device client.
File Description
internal/​usecase/​devices/​certificates.go Extracts certificate normalization from AddCertificate.

Review effort: Balanced

Comment thread internal/usecase/devices/certificates.go Outdated
golangci-lint v2.15.0 reports AddCertificate at cognitive complexity
17 (limit 16). Move base64/PEM decoding and validation into
normalizeCertificate with no behavior change.

An expired certificate or a non-CERTIFICATE PEM block still returns
early without contacting the device, now covered by tests.
@rsdmike
rsdmike force-pushed the refactor/add-certificate-complexity branch from 4de2317 to ca5f267 Compare October 16, 2026 22:06
@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 62.24%. Comparing base (59c10e0) to head (ca5f267).

Files with missing lines Patch % Lines
internal/usecase/devices/certificates.go 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1333      +/-   ##
==========================================
+ Coverage   62.17%   62.24%   +0.06%     
==========================================
  Files         159      159              
  Lines       13414    13417       +3     
==========================================
+ Hits         8340     8351      +11     
+ Misses       5074     5066       -8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rsdmike
rsdmike merged commit 48b0645 into main Oct 16, 2026
22 checks passed
@rsdmike
rsdmike deleted the refactor/add-certificate-complexity branch October 16, 2026 22:12
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.

3 participants