Skip to content

fix: defer keyring initialization to prevent build-time keychain errors#562

Merged
Vad1mo merged 1 commit into
goharbor:mainfrom
chenrui333:fix/lazy-keyring-initialization
Oct 23, 2025
Merged

fix: defer keyring initialization to prevent build-time keychain errors#562
Vad1mo merged 1 commit into
goharbor:mainfrom
chenrui333:fix/lazy-keyring-initialization

Conversation

@chenrui333

Copy link
Copy Markdown
Contributor

seeing some build issue with keychain, and patch to do lazy init

@chenrui333

Copy link
Copy Markdown
Contributor Author

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.

Pull Request Overview

This PR fixes build-time keychain errors by deferring keyring initialization from package init time to first use through lazy initialization.

  • Removed init() function and replaced with ensureKeyringProvider() using sync.Once for thread-safe lazy initialization
  • Added calls to ensureKeyringProvider() in GenerateEncryptionKey() and GetEncryptionKey() functions
  • Prevents keyring system from being accessed during build/package initialization
Comments suppressed due to low confidence (1)

pkg/utils/encryption.go:1

  • The ensureKeyringProvider() call in GetEncryptionKey() lacks test coverage to verify that the keyring provider is properly initialized on first use. Consider adding a test that validates lazy initialization behavior.
// Copyright Project Harbor Authors

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codecov

codecov Bot commented Oct 22, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 6.74%. Comparing base (60ad0bd) to head (93f98b7).
⚠️ Report is 54 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##             main    #562      +/-   ##
=========================================
- Coverage   10.99%   6.74%   -4.25%     
=========================================
  Files         173     258      +85     
  Lines        8671   15382    +6711     
=========================================
+ Hits          953    1037      +84     
- Misses       7612   14239    +6627     
  Partials      106     106              

☔ View full report in Codecov by Sentry.
📢 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.

@chenrui333

Copy link
Copy Markdown
Contributor Author

thoughts of merging this change?

@qcserestipy qcserestipy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@Vad1mo Vad1mo merged commit 7bd83eb into goharbor:main Oct 23, 2025
8 of 9 checks passed
@chenrui333

Copy link
Copy Markdown
Contributor Author

@qcserestipy thanks for the merge, can we cut a new release, this would help with shipping the project in homebrew-core, Homebrew/homebrew-core#250518.

@chenrui333 chenrui333 deleted the fix/lazy-keyring-initialization branch October 25, 2025 13:41
NucleoFusion pushed a commit to NucleoFusion/harbor-cli that referenced this pull request Dec 27, 2025
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.

4 participants