Skip to content

Add support for per-project vulnerability scanner configuration#593

Merged
flbla merged 1 commit into
goharbor:mainfrom
trivoallan:claude/fix-harbor-issue-590-nEkEc
Apr 22, 2026
Merged

Add support for per-project vulnerability scanner configuration#593
flbla merged 1 commit into
goharbor:mainfrom
trivoallan:claude/fix-harbor-issue-590-nEkEc

Conversation

@trivoallan
Copy link
Copy Markdown
Contributor

@trivoallan trivoallan commented Apr 14, 2026

Summary

This PR adds support for configuring vulnerability scanners on a per-project basis in the Harbor Terraform provider, allowing users to override the global default scanner for individual projects.

Key Changes

  • New Client Methods: Added three new methods to client/project.go:

    • GetScannerByName(): Retrieves a scanner by name from the list of available scanners
    • SetProjectScanner(): Assigns a vulnerability scanner to a specific project
    • GetProjectScanner(): Retrieves the assigned scanner name for a project
  • Refactored Scanner Logic: Extracted common scanner lookup logic from client/system.go into the reusable GetScannerByName() method, simplifying SetDefaultScanner() and reducing code duplication

  • Resource Schema Updates:

    • Added vulnerability_scanner optional field to the harbor_project resource
    • Added vulnerability_scanner computed field to the harbor_project data source
  • Resource Lifecycle Management:

    • Scanner is set during project creation via resourceProjectCreate()
    • Scanner is updated when the field changes via resourceProjectUpdate()
    • Scanner is read and synced during resourceProjectRead() and data source read operations
  • Model Addition: Added ProjectScannerBody struct to models/projects.go for API request payloads

  • Documentation: Updated resource and data source documentation to describe the new vulnerability_scanner field

Implementation Details

  • Scanner lookup uses case-insensitive comparison (strings.EqualFold) for robustness
  • The feature gracefully handles missing scanners with appropriate error messages
  • 404 responses when reading project scanners are treated as "no scanner assigned" rather than errors
  • The implementation follows existing patterns in the codebase for resource CRUD operations

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 14, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 17 complexity · 0 duplication

Metric Results
Complexity 17
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes. Give us feedback

@trivoallan trivoallan force-pushed the claude/fix-harbor-issue-590-nEkEc branch from 500000e to 0b75268 Compare April 20, 2026 15:05
Add optional `vulnerability_scanner` attribute to `harbor_project` resource,
allowing users to override the global default scanner on a per-project basis
via the Harbor v2.0 project-level scanner API endpoints.

- Add ProjectScannerBody model for PUT /projects/{id}/scanner
- Add GetScannerByName, SetProjectScanner, GetProjectScanner client functions
- Refactor SetDefaultScanner to reuse GetScannerByName (removes duplication)
- Wire scanner assignment into project Create, Read, and Update handlers
- Expose vulnerability_scanner as computed attribute in data source
- Update resource and data source documentation

https://claude.ai/code/session_012e5CjBngXGn8vJFJewmFWJ
Signed-off-by: Tristan Rivoallan <tristan@rivoallan.net>
@trivoallan trivoallan force-pushed the claude/fix-harbor-issue-590-nEkEc branch from 0b75268 to 0312771 Compare April 22, 2026 04:31
@trivoallan trivoallan marked this pull request as ready for review April 22, 2026 04:33
@trivoallan trivoallan requested a review from a team as a code owner April 22, 2026 04:33
Copy link
Copy Markdown
Contributor

@flbla flbla left a comment

Choose a reason for hiding this comment

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

LGTM

@flbla flbla merged commit 0659e45 into goharbor:main Apr 22, 2026
13 of 14 checks passed
@trivoallan trivoallan deleted the claude/fix-harbor-issue-590-nEkEc branch April 22, 2026 08:23
@trivoallan trivoallan restored the claude/fix-harbor-issue-590-nEkEc branch April 22, 2026 08:23
@trivoallan trivoallan deleted the claude/fix-harbor-issue-590-nEkEc branch April 22, 2026 08:23
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