Skip to content

Commit

Permalink
Display plugin url in MegaLinter output logs + quick fixes (#1358)
Browse files Browse the repository at this point in the history
* Display plugin url in MegaLinter output logs

* [MegaLinter] Apply linters fixes

* Add tflint-aws plugin installation to match new version of tflint

* Fix glibc public key download

* downgrade tflint

* fix sgerrand url

Co-authored-by: nvuillam <nvuillam@users.noreply.github.com>
  • Loading branch information
nvuillam and nvuillam committed Mar 27, 2022
1 parent e5c7389 commit 9340439
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Note: Can be used with `megalinter/megalinter@beta` in your GitHub Action mega-l
- Fixes
- Github Comment Reporter: switch to using a hidden HTML comment to mark the comment, with the current workflow and jobid. This is more robust than the old method. ([[#1355](https://github.com/megalinter/megalinter/issues/1355))
- Allow to provide CI_ACTION_RUN_URL to build hlink for GitHub Comments reporter messages ([[#1341](https://github.com/megalinter/megalinter/issues/1341))
- Display plugin URL in MegaLinter output logs ([[#1340](https://github.com/megalinter/megalinter/issues/1340))
- Fix public glibc public key download

- Linter versions upgrades
- [checkov](https://www.checkov.io/) from 2.0.975 to **2.0.977** on 2022-03-21
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ FROM hadolint/hadolint:v2.9.1-alpine as hadolint
FROM ghcr.io/assignuser/chktex-alpine:latest as chktex
FROM yoheimuta/protolint:latest as protolint
FROM ghcr.io/assignuser/lintr-lib:0.2.0 as lintr-lib
FROM ghcr.io/terraform-linters/tflint:latest as tflint
FROM ghcr.io/terraform-linters/tflint:v0.34.1 as tflint
FROM accurics/terrascan:latest as terrascan
FROM alpine/terragrunt:latest as terragrunt
FROM checkmarx/kics:alpine as kics
Expand Down
2 changes: 2 additions & 0 deletions TEMPLATES/.tflint.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ config {

plugin "aws" {
enabled = true
version = "0.12.0"
source = "github.com/terraform-linters/tflint-ruleset-aws"
deep_check = false
}

Expand Down
2 changes: 1 addition & 1 deletion docs/descriptors/dart_dartanalyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ For more information, see https://www.dartlang.org/tools/analyzer.
```dockerfile
ARG DART_VERSION='2.8.4'
ARG GLIBC_VERSION='2.31-r0'
RUN wget --tries=5 -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
RUN wget --tries=5 -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub \
&& wget --tries=5 -q https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk \
&& apk add --no-cache glibc-${GLIBC_VERSION}.apk && rm glibc-${GLIBC_VERSION}.apk \
&& wget --tries=5 https://storage.googleapis.com/dart-archive/channels/stable/release/${DART_VERSION}/sdk/dartsdk-linux-x64-release.zip -O - -q | unzip -q - \
Expand Down
2 changes: 1 addition & 1 deletion flavors/terraform/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
FROM mvdan/shfmt:latest-alpine as shfmt
FROM hadolint/hadolint:v2.9.1-alpine as hadolint
FROM yoheimuta/protolint:latest as protolint
FROM ghcr.io/terraform-linters/tflint:latest as tflint
FROM ghcr.io/terraform-linters/tflint:v0.34.1 as tflint
FROM accurics/terrascan:latest as terrascan
FROM alpine/terragrunt:latest as terragrunt
FROM checkmarx/kics:alpine as kics
Expand Down
1 change: 1 addition & 0 deletions megalinter/Linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(self, params=None, linter_config=None):
self.active_only_if_file_found = []
self.lint_all_files = False
self.lint_all_other_linters_files = False
self.is_plugin = False
self.pre_commands = None
self.post_commands = None

Expand Down
3 changes: 2 additions & 1 deletion megalinter/descriptors/terraform.megalinter-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ linters:
examples:
- "tflint myfile.tf"
- "tflint -c .tflint.hcl myfile.tf"
downgraded_version: true
install:
dockerfile:
- FROM ghcr.io/terraform-linters/tflint:latest as tflint
- FROM ghcr.io/terraform-linters/tflint:v0.34.1 as tflint
- COPY --from=tflint /usr/local/bin/tflint /usr/bin/
# TERRASCAN
- class: TerrascanLinter
Expand Down
6 changes: 5 additions & 1 deletion megalinter/plugin_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

import requests
import yaml
from megalinter import config, linter_factory, utils


Expand Down Expand Up @@ -37,7 +38,10 @@ def load_plugin(plugin):
# Download plugin and write it in megalinter
try:
r = requests.get(plugin, allow_redirects=True)
open(descriptor_file, "wb").write(r.content)
plugin_descriptor = yaml.safe_load(r.content)
plugin_descriptor["is_plugin"] = True
with open(descriptor_file, "w") as outfile:
yaml.dump(plugin_descriptor, outfile)
logging.info(
f"[Plugins] Loaded plugin descriptor {descriptor_file} from {plugin}"
)
Expand Down
15 changes: 11 additions & 4 deletions megalinter/reporters/ConsoleLinterReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ def manage_activation(self):

def produce_report(self):
linter_version = self.master.get_linter_version()
linter_doc_url = (
f"{DOCS_URL_DESCRIPTORS_ROOT}/{self.master.descriptor_id.lower()}_"
f"{self.master.linter_name.lower().replace('-', '_')}"
)
if self.master.is_plugin is True:
linter_doc_url = (
self.master.linter_url
or self.master.linter_repo
or "[linter_url should be defined on descriptor]"
)
else:
linter_doc_url = (
f"{DOCS_URL_DESCRIPTORS_ROOT}/{self.master.descriptor_id.lower()}_"
f"{self.master.linter_name.lower().replace('-', '_')}"
)
# Linter header prints
msg = [
"",
Expand Down
15 changes: 11 additions & 4 deletions megalinter/reporters/TextReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ def manage_activation(self):

def produce_report(self):
# Doc URL
lang_lower = self.master.descriptor_id.lower()
linter_name_lower = self.master.linter_name.lower().replace("-", "_")
doc_name = f"{lang_lower}_{linter_name_lower}"
doc_url = f"{ML_DOC_URL}/descriptors/{doc_name}/"
if self.master.is_plugin is True:
doc_url = (
self.master.linter_url
or self.master.linter_repo
or "[linter_url should be defined on descriptor]"
)
else:
lang_lower = self.master.descriptor_id.lower()
linter_name_lower = self.master.linter_name.lower().replace("-", "_")
doc_name = f"{lang_lower}_{linter_name_lower}"
doc_url = f"{ML_DOC_URL}/descriptors/{doc_name}/"
# Header lines
text_report_lines = [
f"Results of {self.master.linter_name} linter (version {self.master.get_linter_version()})",
Expand Down

0 comments on commit 9340439

Please sign in to comment.