feat: Add support for Private Vulnerability Reporting#2969
feat: Add support for Private Vulnerability Reporting#2969eslerm wants to merge 1 commit intointegrations:mainfrom
Conversation
|
Hey @eslerm Thank you for your contribution! Could you change your approach here? Instead of adding a new field to |
Add a standalone resource for managing private vulnerability reporting on GitHub repositories, following the pattern established by github_repository_dependabot_security_updates. Includes 404 handling for unavailable repos, archived repo handling in delete, and comprehensive tests including import and private repo validation. Closes integrations#2399
6e22178 to
69c7e18
Compare
|
Rebased onto main and refactored per @deiga's feedback — private vulnerability reporting is now a standalone resource ( The resource follows the same pattern as
Additional improvements over the reference pattern:
Please let me know if I can make improvements! |
| Create: resourceGithubRepositoryPrivateVulnerabilityReportingCreateOrUpdate, | ||
| Read: resourceGithubRepositoryPrivateVulnerabilityReportingRead, | ||
| Update: resourceGithubRepositoryPrivateVulnerabilityReportingCreateOrUpdate, | ||
| Delete: resourceGithubRepositoryPrivateVulnerabilityReportingDelete, | ||
| Importer: &schema.ResourceImporter{ | ||
| State: resourceGithubRepositoryPrivateVulnerabilityReportingImport, |
There was a problem hiding this comment.
Please use the Context-aware functions here
| "repository": { | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| ForceNew: true, | ||
| Description: "The GitHub repository.", | ||
| }, |
There was a problem hiding this comment.
Please adopt the repo rename pattern which has been introduced:
- Remove
ForceNew - Add new
Computedfieldrepository_id - Add
diffRepositorytoCustomizeDiff
|
|
||
| func resourceGithubRepositoryPrivateVulnerabilityReporting() *schema.Resource { | ||
| return &schema.Resource{ | ||
| Create: resourceGithubRepositoryPrivateVulnerabilityReportingCreateOrUpdate, |
There was a problem hiding this comment.
Please add a top-level Describe
| return fmt.Errorf("error setting private vulnerability reporting for repository %s/%s: %w", owner, repoName, err) | ||
| } | ||
| d.SetId(repoName) | ||
| return resourceGithubRepositoryPrivateVulnerabilityReportingRead(d, meta) |
There was a problem hiding this comment.
Every CRUD function should have no calls to other CRUD functions
| if err != nil { | ||
| var ghErr *github.ErrorResponse | ||
| if errors.As(err, &ghErr) && ghErr.Response.StatusCode == http.StatusNotFound { | ||
| log.Printf("[WARN] private vulnerability reporting not available for %s/%s, removing from state", owner, repoName) |
|
|
||
| _ = d.Set("repository", repoName) | ||
|
|
||
| err := resourceGithubRepositoryPrivateVulnerabilityReportingRead(d, meta) |
There was a problem hiding this comment.
Do not call any CRUD functions directly
| func resourceGithubRepositoryPrivateVulnerabilityReportingImport(d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) { | ||
| repoName := d.Id() | ||
|
|
||
| _ = d.Set("repository", repoName) |
| checks := map[string]resource.TestCheckFunc{ | ||
| "before": resource.ComposeTestCheckFunc( | ||
| resource.TestCheckResourceAttr( | ||
| "github_repository_private_vulnerability_reporting.test", "enabled", | ||
| "false", | ||
| ), | ||
| ), | ||
| "after": resource.ComposeTestCheckFunc( | ||
| resource.TestCheckResourceAttr( | ||
| "github_repository_private_vulnerability_reporting.test", "enabled", | ||
| "true", | ||
| ), | ||
| ), | ||
| } |
There was a problem hiding this comment.
Please don't use a separate variable for these
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: config, | ||
| Check: checks["before"], |
There was a problem hiding this comment.
Please use ConfigStateChecks instead
| Config: strings.Replace(config, | ||
| enabled, | ||
| updatedEnabled, 1), |
There was a problem hiding this comment.
Please don't use strings.Replace on the config, rather use fmt.Sprintf
|
Thank you @deiga 🙏 |
Adds private_vulnerability_reporting to the github_repository resource's security_and_analysis block.
Implementation uses dedicated GitHub API endpoints rather than the repository Edit API, since PVR status is not included in the SecurityAndAnalysis response:
Changes:
Resolves #2399