Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core scoped configuration & SECURED_ENV_VARIABLES #2601

Merged
merged 54 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ab8f865
Core: Scope configuration instead of directly using ENV vars
nvuillam Apr 29, 2023
d854952
Fixes
nvuillam Apr 29, 2023
3c4c1a7
Default request id
nvuillam Apr 29, 2023
bf84bc5
Fix sarif test
nvuillam Apr 29, 2023
233e489
Fix get_workspace
nvuillam Apr 29, 2023
45d5468
uuid as string
nvuillam Apr 29, 2023
abed01f
Replace distutils by shutil
nvuillam Apr 29, 2023
df07dfa
PRINT_ALL_FILES = false for test classes
nvuillam Apr 29, 2023
a8a5651
Fixes about scoped config
nvuillam Apr 29, 2023
4c1a754
Revert "PRINT_ALL_FILES = false for test classes"
nvuillam Apr 29, 2023
c0c0cb5
Display request config in header
nvuillam Apr 29, 2023
6059d02
Fix init _config
nvuillam Apr 29, 2023
5d67070
Fix subprocess_env
nvuillam Apr 29, 2023
adae57e
copy node_modules only if there are pre_commands & post_commands
nvuillam Apr 29, 2023
93a8d2c
more logs
nvuillam Apr 29, 2023
5268ad9
Reformat config when must be used for env
nvuillam Apr 29, 2023
6c3dac7
Merge remote-tracking branch 'origin/main' into features/scoped-config
nvuillam Apr 29, 2023
b97a39f
Fix check missing flavors
nvuillam Apr 29, 2023
4358453
Fix config test classes
nvuillam Apr 29, 2023
9e71571
Fix Github Comment reporter
nvuillam Apr 29, 2023
84a3f33
mypy & cspell fixes
nvuillam Apr 29, 2023
bd329f8
[MegaLinter] Apply linters fixes
nvuillam Apr 29, 2023
a23bb62
Ad icu-libs for BICEP linter
nvuillam Apr 29, 2023
39ff029
Fix build script
nvuillam Apr 29, 2023
f9879a5
[MegaLinter] Apply linters fixes
nvuillam Apr 29, 2023
c7845e6
Fix pre_test
nvuillam Apr 29, 2023
c0cfe91
[MegaLinter] Apply linters fixes
nvuillam Apr 29, 2023
b066396
Do not use os.environ to call subprocess
nvuillam Apr 29, 2023
29c44e0
SECURED_ENV_VARIABLES
nvuillam Apr 29, 2023
2f691f8
Fix
nvuillam Apr 29, 2023
dbec3d9
[MegaLinter] Apply linters fixes
nvuillam Apr 29, 2023
800897a
Doc SECURED_ENV_VARIABLES
nvuillam Apr 29, 2023
b7e3a26
Update jsonschema
nvuillam Apr 29, 2023
c12bc8c
Do not use secured environment for pre_commands & post_commands by de…
nvuillam Apr 29, 2023
1bd64b2
[MegaLinter] Apply linters fixes
nvuillam Apr 29, 2023
0eb1ad0
Manage init_config case for test classes
nvuillam Apr 30, 2023
9910ead
Fix test cases __init__
nvuillam Apr 30, 2023
2f36e3f
[MegaLinter] Apply linters fixes
nvuillam Apr 30, 2023
aa4f170
Fix config tests
nvuillam Apr 30, 2023
81fd5d9
[MegaLinter] Apply linters fixes
nvuillam Apr 30, 2023
2963a4d
Fix config class
nvuillam Apr 30, 2023
8db939e
[MegaLinter] Apply linters fixes
nvuillam Apr 30, 2023
4ad65bc
Fix test classes
nvuillam Apr 30, 2023
c3355d4
Merge remote-tracking branch 'origin/features/scoped-config' into fea…
nvuillam Apr 30, 2023
90d08f0
[MegaLinter] Apply linters fixes
nvuillam Apr 30, 2023
d39ecfa
Fix load plugins & secure ENV
nvuillam Apr 30, 2023
c8c0966
Fix powershell_formatter test class
nvuillam Apr 30, 2023
49483ce
[MegaLinter] Apply linters fixes
nvuillam Apr 30, 2023
2a3db8b
Use DELETE_TEST_CLASSES to reset test classes when building
nvuillam Apr 30, 2023
70fed7b
Merge remote-tracking branch 'origin/features/scoped-config' into fea…
nvuillam Apr 30, 2023
88abefb
Documentation
nvuillam Apr 30, 2023
374477f
[MegaLinter] Apply linters fixes
nvuillam Apr 30, 2023
a05602e
Display process number in logs
nvuillam Apr 30, 2023
11796e1
display
nvuillam Apr 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions .automation/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import yaml
from bs4 import BeautifulSoup
from giturlparse import parse
from megalinter import utils
from megalinter import config, utils
from megalinter.constants import (
DEFAULT_DOCKERFILE_APK_PACKAGES,
DEFAULT_RELEASE,
Expand All @@ -47,6 +47,7 @@
UPDATE_CHANGELOG = "--changelog" in sys.argv
IS_LATEST = "--latest" in sys.argv
DELETE_DOCKERFILES = "--delete-dockerfiles" in sys.argv
DELETE_TEST_CLASSES = "--delete-test-classes" in sys.argv

# Release args management
if RELEASE is True:
Expand Down Expand Up @@ -153,7 +154,7 @@ def generate_flavor(flavor, flavor_info):
descriptor_and_linters += [descriptor]
flavor_descriptors += [descriptor["descriptor_id"]]
# Get install instructions at linter level
linters = megalinter.linter_factory.list_all_linters()
linters = megalinter.linter_factory.list_all_linters(({"request_id": "build"}))
requires_docker = False
for linter in linters:
if match_flavor(vars(linter), flavor, flavor_info) is True:
Expand Down Expand Up @@ -596,7 +597,7 @@ def generate_linter_dockerfiles():
if "install" in descriptor:
descriptor_items += [descriptor]
descriptor_linters = megalinter.linter_factory.build_descriptor_linters(
descriptor_file, None
descriptor_file, {"request_id": "build"}
)
# Browse descriptor linters
for linter in descriptor_linters:
Expand Down Expand Up @@ -686,11 +687,12 @@ def generate_linter_dockerfiles():
def generate_linter_test_classes():
test_linters_root = f"{REPO_HOME}/megalinter/tests/test_megalinter/linters"

# Remove all the contents of test_linters_root beforehand so that the result is deterministic
shutil.rmtree(os.path.realpath(test_linters_root))
os.makedirs(os.path.realpath(test_linters_root))
if DELETE_TEST_CLASSES is True:
# Remove all the contents of test_linters_root beforehand so that the result is deterministic
shutil.rmtree(os.path.realpath(test_linters_root))
os.makedirs(os.path.realpath(test_linters_root))

linters = megalinter.linter_factory.list_all_linters()
linters = megalinter.linter_factory.list_all_linters(({"request_id": "build"}))
for linter in linters:
if linter.name is not None:
linter_name = linter.name
Expand Down Expand Up @@ -737,7 +739,7 @@ def list_descriptors_for_build():
descriptor = megalinter.linter_factory.build_descriptor_info(descriptor_file)
descriptors += [descriptor]
descriptor_linters = megalinter.linter_factory.build_descriptor_linters(
descriptor_file
descriptor_file, {"request_id": "build"}
)
linters_by_type[descriptor_linters[0].descriptor_type] += descriptor_linters
DESCRIPTORS_FOR_BUILD_CACHE = descriptors, linters_by_type
Expand Down Expand Up @@ -2468,7 +2470,7 @@ def generate_json_schema_enums():
outfile.write("\n")
# Update list of descriptors and linters in configuration schema
descriptors, _linters_by_type = list_descriptors_for_build()
linters = megalinter.linter_factory.list_all_linters()
linters = megalinter.linter_factory.list_all_linters({"request_id": "build"})
with open(CONFIG_JSON_SCHEMA, "r", encoding="utf-8") as json_file:
json_schema = json.load(json_file)
json_schema["definitions"]["enum_descriptor_keys"]["enum"] = [
Expand All @@ -2489,7 +2491,7 @@ def generate_json_schema_enums():

# Collect linters info from linter url, later used to build link preview card within linter documentation
def collect_linter_previews():
linters = megalinter.linter_factory.list_all_linters()
linters = megalinter.linter_factory.list_all_linters({"request_id": "build"})
# Read file
with open(LINKS_PREVIEW_FILE, "r", encoding="utf-8") as json_file:
data = json.load(json_file)
Expand All @@ -2498,7 +2500,7 @@ def collect_linter_previews():
for linter in linters:
if (
linter.linter_name not in data
or megalinter.config.get("REFRESH_LINTER_PREVIEWS", "false") == "true"
or megalinter.config.get(None, "REFRESH_LINTER_PREVIEWS", "false") == "true"
):
logging.info(
f"Collecting link preview info for {linter.linter_name} at {linter.linter_url}"
Expand Down Expand Up @@ -2527,7 +2529,7 @@ def collect_linter_previews():


def generate_documentation_all_linters():
linters_raw = megalinter.linter_factory.list_all_linters()
linters_raw = megalinter.linter_factory.list_all_linters(({"request_id": "build"}))
linters = []
with open(VERSIONS_FILE, "r", encoding="utf-8") as json_file:
linter_versions = json.load(json_file)
Expand Down Expand Up @@ -3103,7 +3105,7 @@ def update_workflow_linters(file_path, linters):
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[logging.StreamHandler(sys.stdout)],
)

config.init_config("build")
# noinspection PyTypeChecker
collect_linter_previews()
generate_json_schema_enums()
Expand Down
2 changes: 1 addition & 1 deletion .automation/generated/linter-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"standard": "17.0.0",
"stylelint": "15.6.0",
"swiftlint": "0.51.0",
"syft": "0.79.0",
"syft": "0.76.1",
"tekton-lint": "0.6.0",
"terraform-fmt": "1.4.6",
"terragrunt": "0.45.6",
Expand Down
3 changes: 3 additions & 0 deletions .automation/test/sample_project/.mega-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DISABLE:
- REPOSITORY
- SPELL
6 changes: 0 additions & 6 deletions .automation/test/sample_project/groovy_good_01.groovy

This file was deleted.

3 changes: 3 additions & 0 deletions .github/linters/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@
"contextlib",
"contextmanager",
"copypaste",
"copytree",
"coreutils",
"countdef",
"coursier",
Expand Down Expand Up @@ -576,6 +577,7 @@
"disableassertions",
"disablesystemassertions",
"displaymath",
"distutils",
"djlint",
"dockerfilelint",
"dockerfilelintrc",
Expand Down Expand Up @@ -1217,6 +1219,7 @@
"shpca",
"shppa",
"shpss",
"shutil",
"simplexml",
"slshape",
"smallskip",
Expand Down
1 change: 1 addition & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ REPOSITORY_TRIVY_ARGUMENTS:
- "--skip-dirs"
- ".automation/test"
SHOW_ELAPSED_TIME: true
FLAVOR_SUGGESTIONS: false
EMAIL_REPORTER: false
FILEIO_REPORTER: true
JSON_REPORTER: true
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l

- Core
- Use relative file paths to call linters ([#1875](https://github.com/oxsecurity/megalinter/issues/1875))
- Refactor internal configuration management to scope config to a request identifier
- New configuration variable SECURED_ENV_VARIABLES to hide some env vars from environment used when calling linters
- Replace deprecated distutils.copy_tree by shutil.copytree
- Add support for idea plugins autoinstall
- Upgrade base Docker image to python:3.11.3-alpine3.17
- Fix issue preventing plugins to work with flavors
Expand Down
Loading