Skip to content

Commit a86f95d

Browse files
enieuwkfcampbell
andauthored
Add support for disabling the use of the vulnerability management endpoint (#1022)
* Add support for disabling the use of the vulnerability management endpoint * Run make lint Co-authored-by: Keegan Campbell <[email protected]>
1 parent c897f62 commit a86f95d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

github/resource_github_repository.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ func resourceGithubRepository() *schema.Resource {
202202
Type: schema.TypeBool,
203203
Optional: true,
204204
},
205+
"ignore_vulnerability_alerts_during_read": {
206+
Type: schema.TypeBool,
207+
Optional: true,
208+
},
205209
"full_name": {
206210
Type: schema.TypeString,
207211
Computed: true,
@@ -477,11 +481,13 @@ func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) erro
477481
d.Set("template", []interface{}{})
478482
}
479483

480-
vulnerabilityAlerts, _, err := client.Repositories.GetVulnerabilityAlerts(ctx, owner, repoName)
481-
if err != nil {
482-
return fmt.Errorf("Error reading repository vulnerability alerts: %v", err)
484+
if !d.Get("ignore_vulnerability_alerts_during_read").(bool) {
485+
vulnerabilityAlerts, _, err := client.Repositories.GetVulnerabilityAlerts(ctx, owner, repoName)
486+
if err != nil {
487+
return fmt.Errorf("Error reading repository vulnerability alerts: %v", err)
488+
}
489+
d.Set("vulnerability_alerts", vulnerabilityAlerts)
483490
}
484-
d.Set("vulnerability_alerts", vulnerabilityAlerts)
485491

486492
return nil
487493
}

website/docs/r/repository.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ initial repository creation and create the target branch inside of the repositor
103103

104104
* `vulnerability_alerts` (Optional) - Set to `true` to enable security alerts for vulnerable dependencies. Enabling requires alerts to be enabled on the owner level. (Note for importing: GitHub enables the alerts on public repos but disables them on private repos by default.) See [GitHub Documentation](https://help.github.com/en/github/managing-security-vulnerabilities/about-security-alerts-for-vulnerable-dependencies) for details. Note that vulnerability alerts have not been successfully tested on any GitHub Enterprise instance and may be unavailable in those settings.
105105

106+
* `ignore_vulnerability_alerts_during_read` (Optional) - Set to `true` to not call the vulnerability alerts endpoint so the resource can also be used without admin permissions during read.
107+
106108
### GitHub Pages Configuration
107109

108110
The `pages` block supports the following:

0 commit comments

Comments
 (0)