|
26 | 26 | ISO_NO_TZ_RE = re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$") |
27 | 27 | VALID_NAME_RE = re.compile(r"^[A-Za-z0-9_.-]{1,39}$") |
28 | 28 |
|
| 29 | +GENERIC_SECRET_TYPES = ",".join( |
| 30 | + [ |
| 31 | + "http_basic_authentication_header", |
| 32 | + "http_bearer_authentication_header", |
| 33 | + "mongodb_connection_string", |
| 34 | + "mysql_connection_string", |
| 35 | + "openssh_private_key", |
| 36 | + "pgp_private_key", |
| 37 | + "postgres_connection_string", |
| 38 | + "rsa_private_key", |
| 39 | + "password", # Copilot powered secret detection |
| 40 | + ] |
| 41 | +) |
| 42 | + |
29 | 43 |
|
30 | 44 | class RateLimited(Exception): |
31 | 45 | """Rate limited exception.""" |
@@ -54,7 +68,7 @@ def __init__(self, token: str | None = None, hostname="github.com") -> None: |
54 | 68 | self.hostname = hostname |
55 | 69 |
|
56 | 70 | @classmethod |
57 | | - def check_name(self, name: str, scope: str) -> bool: |
| 71 | + def check_name(cls, name: str, scope: str) -> bool: |
58 | 72 | """Check the name is valid.""" |
59 | 73 | # check repo slug has <owner</<repo> format or org/Enterprise name is valid |
60 | 74 | if scope == "repo": |
@@ -112,7 +126,7 @@ def query( |
112 | 126 | if paging is None: |
113 | 127 | try: |
114 | 128 | result = self._do(url, method, data=data) |
115 | | - yield result |
| 129 | + yield result.json() |
116 | 130 | except Exception as e: |
117 | 131 | LOG.error("Error: %s", e) |
118 | 132 | # show traceback without raising the exception |
@@ -161,6 +175,8 @@ def construct_api_url( |
161 | 175 |
|
162 | 176 | path = api_path + scope_path + endpoint |
163 | 177 |
|
| 178 | + query_params = {} |
| 179 | + |
164 | 180 | if paging is None: |
165 | 181 | query_params = {} |
166 | 182 | elif paging == "cursor": |
@@ -314,7 +330,7 @@ def paginate( |
314 | 330 | break |
315 | 331 |
|
316 | 332 | if progress: |
317 | | - pbar.update(1) |
| 333 | + pbar.update(1) # type: ignore |
318 | 334 |
|
319 | 335 | LOG.debug(data) |
320 | 336 |
|
@@ -413,9 +429,14 @@ def list_secret_scanning_alerts( |
413 | 429 | since: datetime.datetime | None = None, |
414 | 430 | scope: str = "org", |
415 | 431 | bypassed: bool = False, |
| 432 | + generic: bool = False, |
416 | 433 | ) -> Generator[dict, None, None]: |
417 | 434 | """List secret scanning alerts for a GitHub repository, organization or Enterprise.""" |
418 | 435 | query = {"state": state} if state is not None else {} |
| 436 | + |
| 437 | + if generic: |
| 438 | + query["secret_type"] = GENERIC_SECRET_TYPES |
| 439 | + |
419 | 440 | alerts = self.query( |
420 | 441 | scope, |
421 | 442 | name, |
|
0 commit comments