GitGuardian / ggshield

Find and fix 400+ types of hardcoded secrets and 70+ types of infrastructure-as-code misconfigurations.
https://gitguardian.com
MIT License
1.59k stars 139 forks source link

Disable color codes in CLI output #858

Open thomascube opened 4 months ago

thomascube commented 4 months ago

Is your feature request related to a problem? Please describe.

We're running ggshield in a shell environment where color codes are not supported. The output is collected in a log file and when viewing that file the output is hard to read. See the example below.

Describe the solution you'd like

An option to enable/disable colored output (e.g. --no-colors) or an according environment variable would be helpful to disable colors where not desired.

Additional context

This is how the output looks in our environment:

[ggshield-scan - scan]  
[ggshield-scan - scan]  commit 120xxxxxxxxxxxxxxxxxxxxxxxxx
[ggshield-scan - scan]  Author: xxxxxxx <some.one@example.com>
[ggshield-scan - scan]  Date: Mon Mar 4 12:20:57 2024 +0100
[ggshield-scan - scan] 
[ggshield-scan - scan]  > commit://670ee851eb490c9af1b9ddc54f6a646277bcb9d4/charts/test-chart/values.yaml: 1 incident detected
[ggshield-scan - scan] 
[ggshield-scan - scan]  >> Secret detected: Microsoft Teams webhook
[ggshield-scan - scan]     Validity: Valid
[ggshield-scan - scan]     Occurrences: 1
[ggshield-scan - scan]     Known by GitGuardian dashboard: YES
[ggshield-scan - scan]     Incident URL: https://ccccccccccccc
[ggshield-scan - scan]     Secret SHA: ba1b5876828384cd247fcada027883ed01a05fe10e03afc13ce97d0f6544f568
[ggshield-scan - scan] 
[ggshield-scan - scan]     83 | 
[ggshield-scan - scan]     84 | honeypot:
[ggshield-scan - scan]     85 | …_WEBHOOK: https://xxxxxx.webhook.office.com/we****************-****-****-****-*********************-****-****-****-***********************************************************9c6ea-782f-4fcf-a099-bea8471a6177"…
[ggshield-scan - scan]                     
[ggshield-scan - scan]  
thomascube commented 4 months ago

Although not documented (or I wasn't able to find it) but setting the NO_COLOR env var does the trick. You can therefore close the issue but adding this to the documentation would maybe help others.

agateau-gg commented 4 months ago

Hi, thanks for your feedback.

NO_COLOR is indeed not documented. I am going to file an issue against our doc to fix this.

Right now ggshield disables color when the output is redirected to a file, unless it recognizes it's running in a CI with color support. This needs to be changed so that color is not enabled when redirected to a file even if it's running in a CI with color support.