Skip to content
Snippets Groups Projects
Unverified Commit b77e4e7e authored by Anze Luzar's avatar Anze Luzar
Browse files

Add xOpera validate and Checkstyle

parent 828fb454
No related branches found
No related tags found
No related merge requests found
...@@ -69,10 +69,10 @@ installRequiredNpmModules() { ...@@ -69,10 +69,10 @@ installRequiredNpmModules() {
} }
installPythonModules() { installPythonModules() {
pip install opera==0.6.8
pip install pylint==2.9.6 pip install pylint==2.9.6
pip install gixy==0.1.20 pip install gixy==0.1.20
pip install ansible-lint==5.1.2 pip install ansible-lint==5.1.2
pip install ansible==4.3.0
pip install yamllint==1.26.1 pip install yamllint==1.26.1
pip install bandit==1.7.0 pip install bandit==1.7.0
pip install safety==1.10.3 pip install safety==1.10.3
......
from os import listdir
from typing import Optional
import iac_scan_runner.vars as env
from iac_scan_runner.check import Check
from iac_scan_runner.check_output import CheckOutput
from iac_scan_runner.check_target_entity_type import CheckTargetEntityType
from iac_scan_runner.utils import run_command
from pydantic import SecretStr
class CheckStyle(Check):
def __init__(self):
super().__init__("checkstyle", "Checkstyle is a tool for checking Java source code for adherence to a Code "
"Standard or set of validation rules (best practices)",
CheckTargetEntityType.iac)
self._config_filename = "javalint.xml"
def configure(self, config_filename: Optional[str], secret: Optional[SecretStr]) -> CheckOutput:
if config_filename:
self._config_filename = config_filename
return CheckOutput(f'Check: {self.name} has been configured successfully.', 0)
else:
raise Exception(f'Check: {self.name} requires you to pass a configuration file.')
def run(self, directory: str) -> CheckOutput:
output = ""
rc = 0
for filename in listdir(directory):
if filename.endswith(".java"):
check_output = run_command(
f'java -jar {env.CHECK_STYLE_PATH} -c {env.CONFIG_DIR}/{self._config_filename} {filename}',
directory
)
output += check_output.output + "\n"
rc += check_output.rc
if not output:
return CheckOutput("There are no Java files to check.", 0)
return CheckOutput(output, rc)
from iac_scan_runner.check import Check
from iac_scan_runner.check_output import CheckOutput
from iac_scan_runner.check_target_entity_type import CheckTargetEntityType
from iac_scan_runner.utils import run_command
class OperaToscaCheck(Check):
def __init__(self):
super().__init__("xopera", "A TOSCA orchestrator that can validate TOSCA CSARs", CheckTargetEntityType.iac)
def run(self, directory: str) -> CheckOutput:
return run_command(f'opera validate .', directory)
...@@ -6,6 +6,7 @@ import iac_scan_runner.vars as env ...@@ -6,6 +6,7 @@ import iac_scan_runner.vars as env
from fastapi import UploadFile from fastapi import UploadFile
from iac_scan_runner.checks.ansible_lint import AnsibleLintCheck from iac_scan_runner.checks.ansible_lint import AnsibleLintCheck
from iac_scan_runner.checks.bandit import BanditCheck from iac_scan_runner.checks.bandit import BanditCheck
from iac_scan_runner.checks.checkstyle import CheckStyle
from iac_scan_runner.checks.es_lint import ESLintCheck from iac_scan_runner.checks.es_lint import ESLintCheck
from iac_scan_runner.checks.git_leaks import GitLeaksCheck from iac_scan_runner.checks.git_leaks import GitLeaksCheck
from iac_scan_runner.checks.git_secrets import GitSecretsCheck from iac_scan_runner.checks.git_secrets import GitSecretsCheck
...@@ -21,6 +22,7 @@ from iac_scan_runner.checks.terrascan import TerrascanCheck ...@@ -21,6 +22,7 @@ from iac_scan_runner.checks.terrascan import TerrascanCheck
from iac_scan_runner.checks.tflint import TFLintCheck from iac_scan_runner.checks.tflint import TFLintCheck
from iac_scan_runner.checks.tfsec import TfsecCheck from iac_scan_runner.checks.tfsec import TfsecCheck
from iac_scan_runner.checks.ts_lint import TSLintCheck from iac_scan_runner.checks.ts_lint import TSLintCheck
from iac_scan_runner.checks.xopera import OperaToscaCheck
from iac_scan_runner.checks.yamllint import YamlLintCheck from iac_scan_runner.checks.yamllint import YamlLintCheck
from iac_scan_runner.utils import generate_random_pathname, unpack_archive_to_dir from iac_scan_runner.utils import generate_random_pathname, unpack_archive_to_dir
from pydantic import SecretStr from pydantic import SecretStr
...@@ -34,6 +36,7 @@ class ScanRunner: ...@@ -34,6 +36,7 @@ class ScanRunner:
def init_checks(self): def init_checks(self):
"""Initiate predefined check objects""" """Initiate predefined check objects"""
xopera = OperaToscaCheck()
ansible_lint = AnsibleLintCheck() ansible_lint = AnsibleLintCheck()
tflint = TFLintCheck() tflint = TFLintCheck()
tfsec = TfsecCheck() tfsec = TfsecCheck()
...@@ -52,8 +55,10 @@ class ScanRunner: ...@@ -52,8 +55,10 @@ class ScanRunner:
ts_lint = TSLintCheck() ts_lint = TSLintCheck()
htmlhint = HtmlHintCheck() htmlhint = HtmlHintCheck()
stylelint = StyleLintCheck() stylelint = StyleLintCheck()
checkstyle = CheckStyle()
self.iac_checks = { self.iac_checks = {
xopera.name: xopera,
ansible_lint.name: ansible_lint, ansible_lint.name: ansible_lint,
tflint.name: tflint, tflint.name: tflint,
tfsec.name: tfsec, tfsec.name: tfsec,
...@@ -71,7 +76,8 @@ class ScanRunner: ...@@ -71,7 +76,8 @@ class ScanRunner:
es_lint.name: es_lint, es_lint.name: es_lint,
ts_lint.name: ts_lint, ts_lint.name: ts_lint,
htmlhint.name: htmlhint, htmlhint.name: htmlhint,
stylelint.name: stylelint stylelint.name: stylelint,
checkstyle.name: checkstyle
} }
def _init_iac_dir(self, iac_file: UploadFile): def _init_iac_dir(self, iac_file: UploadFile):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment