Skip to content

Commit

Permalink
feat: multi language support (#182)
Browse files Browse the repository at this point in the history
Adds multi language support.
  • Loading branch information
rgraue authored Jul 12, 2023
1 parent 4d26858 commit 666fb44
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 291 deletions.
35 changes: 17 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
exclude: ^(?:.+/)?\.idea(?P<ps_d>/).*$
repos:
- hooks:
- id: python-use-type-annotations
repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
- hooks:
- args:
- --exclude
- tests/
- --severity-level
- medium
id: bandit
repo: https://github.com/PyCQA/bandit
rev: 1.7.4
- hooks:
- id: black
repo: https://github.com/psf/black
rev: 22.10.0
- hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -24,24 +40,7 @@ repos:
- id: check-yaml
repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
- hooks:
- id: python-use-type-annotations
repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
- hooks:
- id: detect-secrets
repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
- hooks:
- args:
- --exclude
- tests/
- --severity-level
- medium
id: bandit
repo: https://github.com/PyCQA/bandit
rev: 1.7.4
- hooks:
- id: black
repo: https://github.com/psf/black
rev: 22.10.0
28 changes: 11 additions & 17 deletions secureli/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def verify_install(
return self._install_secureli(folder_path, always_yes)
else:
available_version = self.action_deps.language_support.version_for_language(
config.languages[0]
config.languages
)

# Check for a new version and prompt for upgrade if available
Expand All @@ -109,7 +109,7 @@ def verify_install(
# Validates the current .pre-commit-config.yaml against the generated config
config_validation_result = (
self.action_deps.language_support.validate_config(
language=config.languages[0]
languages=config.languages
)
)

Expand All @@ -119,7 +119,7 @@ def verify_install(
return self._update_secureli(always_yes)

self.action_deps.echo.print(
f"SeCureLI is installed and up-to-date (language = {config.languages[0]})"
f"SeCureLI is installed and up-to-date (languages = {config.languages})"
)
return VerifyResult(
outcome=VerifyOutcome.UP_TO_DATE,
Expand Down Expand Up @@ -151,9 +151,7 @@ def _upgrade_secureli(
)

try:
metadata = self.action_deps.language_support.apply_support(
config.languages[0]
)
metadata = self.action_deps.language_support.apply_support(config.languages)

# Update config with new version installed and save it
config.version_installed = metadata.version
Expand Down Expand Up @@ -208,14 +206,10 @@ def _install_secureli(self, folder_path: Path, always_yes: bool) -> VerifyResult
self.action_deps.echo.print(
f"- {language}: {percentage:.0%}", color=Color.MAGENTA, bold=True
)
overall_language = list(analyze_result.language_proportions.keys())
self.action_deps.echo.print(
f"Overall Detected Language: {overall_language[0]}"
)
languages = list(analyze_result.language_proportions.keys())
self.action_deps.echo.print(f"Overall Detected Languages: {languages}")

metadata = self.action_deps.language_support.apply_support(
overall_language[0]
)
metadata = self.action_deps.language_support.apply_support(languages)

except (ValueError, LanguageNotSupportedError, InstallFailedError) as e:
self.action_deps.echo.error(
Expand All @@ -226,25 +220,25 @@ def _install_secureli(self, folder_path: Path, always_yes: bool) -> VerifyResult
)

config = SecureliConfig(
languages=overall_language,
languages=languages,
version_installed=metadata.version,
)
self.action_deps.secureli_config.save(config)

if secret_test_id := metadata.security_hook_id:
self.action_deps.echo.print(
f"{config.languages[0]} supports secrets detection; running {secret_test_id}."
f"{config.languages} supports secrets detection; running {secret_test_id}."
)
self.action_deps.scanner.scan_repo(
ScanMode.ALL_FILES, specific_test=secret_test_id
)
else:
self.action_deps.echo.warning(
f"{config.languages[0]} does not support secrets detection, skipping"
f"{config.languages} does not support secrets detection, skipping"
)

self.action_deps.echo.print(
f"SeCureLI has been installed successfully (language = {config.languages[0]})"
f"SeCureLI has been installed successfully (languages = {config.languages})"
)

return VerifyResult(
Expand Down
27 changes: 27 additions & 0 deletions secureli/resources/files/base-pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-toml
- id: check-json
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: detect-aws-credentials
args: [--allow-missing-credentials]
- id: detect-private-key
- id: name-tests-test
args: [--pytest-test-first]
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
20 changes: 0 additions & 20 deletions secureli/resources/files/csharp-pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-added-large-files
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-json
- id: check-xml
- id: check-yaml
- id: detect-aws-credentials
args: [--allow-missing-credentials]
- id: detect-private-key
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
- repo: local
hooks:
# Note: The dotnet format pre-commit setup combines poorly to be tightly coupled with
Expand Down
23 changes: 1 addition & 22 deletions secureli/resources/files/go-pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-added-large-files
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-toml
- id: check-json
- id: check-xml
- id: check-yaml
- id: detect-aws-credentials
args: [--allow-missing-credentials]
- id: detect-private-key
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.53.3
hooks:
Expand Down
24 changes: 2 additions & 22 deletions secureli/resources/files/java-pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-added-large-files
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-toml
- id: check-json
- id: check-xml
- id: check-yaml
- id: detect-aws-credentials
args: [--allow-missing-credentials]
- id: detect-private-key
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
- repo: https://github.com/rgraue/pre-commit-mirror-checkstyle
rev: v0.1.15
- repo: https://github.com/slalombuild/pre-commit-mirror-checkstyle
rev: v0.1.1
hooks:
- id: checkstyle-java
27 changes: 0 additions & 27 deletions secureli/resources/files/javascript-pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,4 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-added-large-files
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-toml
- id: check-json
- id: check-xml
- id: check-yaml
- id: detect-aws-credentials
args: [--allow-missing-credentials]
- id: detect-private-key
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
- repo: local
hooks:
- id: config
language: system
entry: ls
name: config
- repo: https://github.com/pre-commit/mirrors-eslint
rev: 'v8.42.0'
hooks:
Expand Down
26 changes: 0 additions & 26 deletions secureli/resources/files/python-pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-toml
- id: check-json
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: detect-aws-credentials
args: [--allow-missing-credentials]
- id: detect-private-key
- id: name-tests-test
args: [--pytest-test-first]
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: python-use-type-annotations
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
Expand Down
7 changes: 0 additions & 7 deletions secureli/resources/files/swift-pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
Expand Down
7 changes: 0 additions & 7 deletions secureli/resources/files/terraform-pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
Expand Down
21 changes: 0 additions & 21 deletions secureli/resources/files/typescript-pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-added-large-files
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-toml
- id: check-json
- id: check-xml
- id: check-yaml
- id: detect-aws-credentials
args: [--allow-missing-credentials]
- id: detect-private-key
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
- repo: https://github.com/pre-commit/mirrors-eslint
rev: 'v8.42.0'
hooks:
Expand Down
Loading

0 comments on commit 666fb44

Please sign in to comment.