-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add enterprise-wide code scanning alerts for Enterprise Server and GH…
…AE (#3) * start work on ghes/ghae support * add csv files to gitignore * add enterprise report function * add enterprise-scope code scanning reporting * update readme * add dependency review check * mess with line length in linter * mess with linter * still messing with linter
- Loading branch information
1 parent
d15982a
commit bc9ffe2
Showing
8 changed files
with
217 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"MD013": false, | ||
"line-length": false, | ||
"MD033": { "allowed_elements": ["br"] } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: "Dependency Review" | ||
on: [pull_request] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
dependency-review: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Checkout Repository" | ||
uses: actions/checkout@v3 | ||
- name: "Dependency Review" | ||
uses: actions/dependency-review-action@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,3 +130,6 @@ dmypy.json | |
|
||
# Notes, etc. | ||
swap.md | ||
|
||
# CSV files | ||
*.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# This holds all the logic for the various enterprise differences. | ||
|
||
# Imports | ||
import csv | ||
from time import sleep | ||
import requests | ||
|
||
|
||
def get_enterprise_version(api_endpoint): | ||
""" | ||
Get the version of GitHub Enterprise. It'll be used to account for | ||
differences between GHES and GHAE and GHEC, like the organization secret | ||
scanning API not existing outside GHEC. | ||
GitHub AE returns "GitHub AE" as of M2 | ||
GHES returns the version of GHES that's installed (e.g. "3.4.0") | ||
""" | ||
if api_endpoint != "https://api.github.com": | ||
url = "{}/meta".format(api_endpoint) | ||
response = requests.get(url) | ||
if "installed_version" in response.json(): | ||
return response.json()["installed_version"] | ||
else: | ||
return "unknown version of GitHub" | ||
else: | ||
return "GHEC" | ||
|
||
|
||
def get_repo_report(url, github_pat): | ||
""" | ||
Get the `all_repositories.csv` report from GHES / GHAE. | ||
""" | ||
headers = { | ||
"Accept": "application/vnd.github.v3+json", | ||
"Authorization": "token {}".format(github_pat), | ||
} | ||
url = "{}/stafftools/reports/all_repositories.csv".format(url) | ||
response = requests.get(url, headers=headers) | ||
if response.status_code == 202: # report needs to be generated | ||
while response.status_code == 202: | ||
print("Waiting a minute for the report to be generated ...") | ||
sleep(60) | ||
response = requests.get(url, headers=headers) | ||
elif response.status_code == 200: # report is ready | ||
print("Report is ready! Reading it now ...") | ||
for row in csv.reader(response.text.splitlines()): # skip user repos | ||
if row[2] == "Organization": | ||
yield "{}/{}".format(row[3], row[5]) | ||
else: | ||
pass | ||
else: # something went wrong with fetching the report | ||
exit("Error: {}".format(response.status_code)) |