-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alex Goodman <[email protected]> Signed-off-by: Alex Goodman <[email protected]>
- Loading branch information
Showing
18 changed files
with
1,239 additions
and
148 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
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
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,70 @@ | ||
import copy | ||
import os | ||
from dataclasses import dataclass, field | ||
|
||
from vunnel import provider, schema | ||
|
||
from .parser import Parser, namespace | ||
|
||
|
||
@dataclass | ||
class Config: | ||
token: str = "env:GITHUB_TOKEN" | ||
api_url: str = "https://api.github.com/graphql" | ||
runtime: provider.RuntimeConfig = field( | ||
default_factory=lambda: provider.RuntimeConfig(existing_input=provider.InputStatePolicy.KEEP) | ||
) | ||
request_timeout: int = 125 | ||
|
||
def __post_init__(self): | ||
if self.token.startswith("env:"): | ||
self.token = os.environ.get(self.token[4:], "") | ||
|
||
def __str__(self): | ||
# sanitize secrets from any output | ||
tok_value = self.token | ||
str_value = super().__str__() | ||
if not tok_value: | ||
return str_value | ||
return str_value.replace(tok_value, "********") | ||
|
||
|
||
class Provider(provider.Provider): | ||
name = "github" | ||
|
||
def __init__(self, root: str, config: Config): | ||
super().__init__(root, runtime_cfg=config.runtime) | ||
self.config = config | ||
|
||
self.logger.debug(f"config: {config}") | ||
|
||
self.schema = schema.GithubSecurityAdvisorySchema() | ||
self.parser = Parser( | ||
workspace=self.input, | ||
token=config.token, | ||
api_url=config.api_url, | ||
download_timeout=self.config.request_timeout, | ||
logger=self.logger, | ||
) | ||
|
||
def update(self) -> list[str]: | ||
|
||
with self.results_writer() as writer: | ||
for advisory in self.parser.get(): | ||
all_fixes = copy.deepcopy(advisory.get("FixedIn")) if isinstance(advisory.get("FixedIn"), list) else [] | ||
for ecosystem in advisory.ecosystems: | ||
|
||
advisory["namespace"] = f"{namespace}:{ecosystem}" | ||
|
||
# filter the list of fixes for this ecosystem | ||
advisory["FixedIn"] = [item for item in all_fixes if item.get("ecosystem") == ecosystem] | ||
|
||
vuln_id = advisory["ghsaId"] | ||
|
||
writer.write( | ||
identifier=f"{namespace}-{vuln_id}".lower(), | ||
schema=self.schema, | ||
payload={"Vulnerability": {}, "Advisory": dict(advisory)}, | ||
) | ||
|
||
return [self.parser.api_url] |
Oops, something went wrong.