-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from syn-4ck/dev
Send refactors to main
- Loading branch information
Showing
20 changed files
with
1,138 additions
and
260 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "pip" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" |
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 |
---|---|---|
@@ -1,41 +1,58 @@ | ||
import os | ||
|
||
#from guesslang import Guess | ||
|
||
def _detect_technologies (code_path): | ||
technologies = [] | ||
for root,_,f_names in os.walk(code_path): | ||
for f in f_names: | ||
tech = _guess_programming_language_from_extension(os.path.join(root, f)) | ||
if tech is not None: | ||
technologies.append(tech) | ||
return list(dict.fromkeys(technologies)) | ||
|
||
def _guess_programming_language_from_extension (filepath): | ||
from typing import List, Dict | ||
|
||
def _detect_technologies(code_path: str) -> List[str]: | ||
""" | ||
Detects the programming technologies used in the given code path. | ||
Args: | ||
code_path: The path to the directory containing the code. | ||
Returns: | ||
A list of programming technologies used in the code. | ||
""" | ||
return list(set(_guess_programming_language_from_extension(os.path.join(root, f)) | ||
for root, _, f_names in os.walk(code_path) | ||
for f in f_names | ||
if _guess_programming_language_from_extension(os.path.join(root, f)))) | ||
|
||
def _guess_programming_language_from_extension(filepath: str) -> str: | ||
""" | ||
Guesses the programming language based on the file extension of the given file path. | ||
Parameters: | ||
filepath (str): The path of the file. | ||
Returns: | ||
str: The file extension indicating the programming language. | ||
""" | ||
_, file_extension = os.path.splitext(filepath) | ||
return file_extension | ||
|
||
def select_tools(scan_fullpath, config, fafnir_configuration): | ||
def select_tools(scan_fullpath: str, config: Dict[str, dict], fafnir_configuration: Dict[str, list]) -> List[str]: | ||
""" | ||
Generates a list of tools based on the detected technologies in the given scan_fullpath. | ||
list_tools = [] | ||
Parameters: | ||
- scan_fullpath (str): The full path of the scan. | ||
- config (Dict[str, dict]): The configuration dictionary. | ||
- fafnir_configuration (Dict[str, list]): The fafnir configuration dictionary. | ||
technologies = _detect_technologies(scan_fullpath) | ||
Returns: | ||
- list[str]: A list of tools based on the detected technologies, excluding any tools specified in the fafnir configuration. | ||
exclude_tools = [] | ||
if fafnir_configuration.get('exclude-tools') is not None: | ||
exclude_tools = fafnir_configuration.get('exclude-tools') | ||
""" | ||
technologies = _detect_technologies(scan_fullpath) | ||
exclude_tools = fafnir_configuration.get('exclude-tools', []) | ||
|
||
for tech in list(config.get('technologies').keys()): | ||
supported_technologies = config.get('technologies').get(tech).get('extensions') | ||
for code_technology in technologies: | ||
if code_technology in supported_technologies: | ||
list_tools.extend(x for x in config.get('technologies').get(tech).get('tools') if x not in list_tools and x not in exclude_tools) | ||
list_tools = [ | ||
tool | ||
for tech in config.get('technologies').keys() | ||
for code_technology in technologies | ||
if code_technology in config.get('technologies').get(tech).get('extensions') | ||
for tool in config.get('technologies').get(tech).get('tools') | ||
if tool not in exclude_tools | ||
] | ||
|
||
return list_tools | ||
|
||
# Deprecated: Not so eficient | ||
#def _guess_programming_language_from_file (filepath): | ||
# with open(filepath, 'r') as file: | ||
# file_content = file.read() | ||
# guess = Guess() | ||
# return guess.language_name(file_content) |
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 |
---|---|---|
@@ -1,11 +1,163 @@ | ||
|
||
class Dependency: | ||
|
||
def __init__(self, name, version, location, package_manager, language, licenses, purl): | ||
def __init__(self) -> None: | ||
pass | ||
|
||
''' | ||
def __init__(self, name:str, version:str, location:str, package_manager:str, language, licenses, purl): | ||
self.name = name | ||
self.version = version | ||
self.location = location | ||
self.package_manager = package_manager | ||
self.language = language | ||
self.licenses = licenses | ||
self.purl = purl | ||
''' | ||
|
||
def get_name(self): | ||
""" | ||
Get the name attribute. | ||
Returns: | ||
str: The name attribute. | ||
""" | ||
return self.name | ||
|
||
def set_name(self, name): | ||
""" | ||
Set the name attribute. | ||
Parameters: | ||
name (str): The new name attribute. | ||
Returns: | ||
None | ||
""" | ||
self.name = name | ||
|
||
def get_version(self): | ||
""" | ||
Get the version attribute. | ||
Returns: | ||
str: The version attribute. | ||
""" | ||
return self.version | ||
|
||
def set_version(self, version): | ||
""" | ||
Set the version attribute. | ||
Parameters: | ||
version (str): The new version attribute. | ||
Returns: | ||
None | ||
""" | ||
self.version = version | ||
|
||
def get_location(self): | ||
""" | ||
Get the location attribute. | ||
Returns: | ||
str: The location attribute. | ||
""" | ||
return self.location | ||
|
||
def set_location(self, location): | ||
""" | ||
Set the location attribute. | ||
Parameters: | ||
location (str): The new location attribute. | ||
Returns: | ||
None | ||
""" | ||
self.location = location | ||
|
||
def get_package_manager(self): | ||
""" | ||
Get the package_manager attribute. | ||
Returns: | ||
str: The package_manager attribute. | ||
""" | ||
return self.package_manager | ||
|
||
def set_package_manager(self, package_manager): | ||
""" | ||
Set the package_manager attribute. | ||
Parameters: | ||
package_manager (str): The new package_manager attribute. | ||
Returns: | ||
None | ||
""" | ||
self.package_manager = package_manager | ||
|
||
def get_language(self): | ||
""" | ||
Get the language attribute. | ||
Returns: | ||
str: The language attribute. | ||
""" | ||
return self.language | ||
|
||
def set_language(self, language): | ||
""" | ||
Set the language attribute. | ||
Parameters: | ||
language (str): The new language attribute. | ||
Returns: | ||
None | ||
""" | ||
self.language = language | ||
|
||
def get_licenses(self): | ||
""" | ||
Get the licenses attribute. | ||
Returns: | ||
list: The licenses attribute. | ||
""" | ||
return self.licenses | ||
|
||
def set_licenses(self, licenses): | ||
""" | ||
Set the licenses attribute. | ||
Parameters: | ||
licenses (list): The new licenses attribute. | ||
Returns: | ||
None | ||
""" | ||
self.licenses = licenses | ||
|
||
def get_purl(self): | ||
""" | ||
Get the purl attribute. | ||
Returns: | ||
str: The purl attribute. | ||
""" | ||
return self.purl | ||
|
||
def set_purl(self, purl): | ||
""" | ||
Set the purl attribute. | ||
Parameters: | ||
purl (str): The new purl attribute. | ||
Returns: | ||
None | ||
""" | ||
self.purl = purl |
Oops, something went wrong.