8000 Add support for suppression criteria by martinschaef · Pull Request #25 · aws/aws-codeguru-cli · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@martinschaef
Copy link
Contributor
@martinschaef martinschaef commented Jun 29, 2022

Adds support for cli-specific suppression mechanisms in .codeguru-ignore.yml and bumps the version to 0.1.0:

version: 1.0  # The Version field is mandatory. All other fields are optional. 

# The CodeGuru Reviewer CLI produces a recommendations.json file which contains deterministic IDs for each
# recommendation. This ID can be excluded so that this recommendation will not be reported in future runs of the
# CLI.
ExcludeById:
- '4d2c43618a2dac129818bef77093730e84a4e139eef3f0166334657503ecd88d'

# We can tell the CLI to exclude all recommendations below a certain severity. This can be useful in CICD integration.
ExcludeBelowSeverity: 'HIGH'

# We can exclude all recommendations that have a certain tag. Available Tags can be found here:
# https://docs.aws.amazon.com/codeguru/detector-library/java/tags/
# https://docs.aws.amazon.com/codeguru/detector-library/python/tags/
ExcludeTags:
  - 'maintainability'

# We can also exclude recommendations by Detector ID. Detector IDs can be found here:
# https://docs.aws.amazon.com/codeguru/detector-library
ExcludeRecommendations:
# Ignore all recommendations for a given Detector ID 
  - detectorId: 'java/aws-region-enumeration@v1.0'
# Ignore all recommendations for a given Detector ID in a provided set of locations.
# Locations can be written as Unix GLOB expressions using wildcard symbols.
  - detectorId: 'java/aws-region-enumeration@v1.0'
    Locations:
      - 'src/main/java/com/folder01/*.java'

# Excludes all recommendations in the provided files. Files can be provided as Unix GLOB expressions.
ExcludeFiles:
  - tst/**

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@martinschaef martinschaef requested a review from awsgaucho June 29, 2022 18:10
Comment on lines 191 to 192
./gradlew properties -q | grep "version:"
./gradlew properties -q | grep "version:" | awk '{print $2}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need both lines?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you need neither and this is a left-over. Looks like the one below is the one that matters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will remove

# CodeGuru Reviewer CLI Wrapper
Simple CLI wrapper for CodeGuru reviewer that provides a one-line command to scan a local clone of a repository and
receive results. This CLI wraps the [AWS CLI](https://aws.amazon.com/cli/) commands to communicated with
[AWS CodeGuru Reviewer](https://aws.amazon.com/codeguru/). Using CodeGuru Reviewer may generate metering fees
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[not from this PR] Typo in "communicated" in the line above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

README.md Outdated

### Prerequisites

To run the CLI, we need to have a version of git, Java (e.g., [Amazon Corretto](https://aws.amazon.com/corretto/?filtered-posts.sort-by=item.additionalFields.createdDate&filtered-posts.sort-order=desc)) and the [AWS Command Line interface](https://aws.amazon.com/cli/) installed. Verify that both application are installed on our machine by running:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both applications

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

README.md Outdated

### Scan an Example

Now, lets download an example project (requires Maven):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

README.md Outdated

You can use this CLI to run CodeGuru from inside your CI/CD pipeline. See [this action](.github/workflows/self-test-and-release.yml#L30-L41) as an example. First, you need credentials for a role with the permissions mentioned above. If you already scanned
the repository once with the CLI, the S3 bucket has been created, and the you do not need the `s3:CreateBucket*` permission anymore.
# We can tell the CLI to exclude all recommendations below a certain severity. This can be useful in CICD integration.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: CI/CD for consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

}
}

// try load the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

complete or remove comment

Log.info("Analysis finished.");
if (main.failOnRecommendations && !results.isEmpty()) {
RecommendationPrinter.print(results);
System.exit(5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log a message explaining why we are exiting with an error code?

The person who debugs why this is returning errcode 5 may not be the same one who decided to enable the flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point


public class CodeInsightReport {

/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove dead code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

sb.append(recommendation.description());
sb.append("\n");
if (severityToInt(recommendation) < 2) {
Log.error(sb.toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may look like that CLI wrapper itself hit an error. Aren't INFO messages with Severity: FOOBAR enough? Otherwise you're saying the same thing twice in different ways. I know this may allow loglevel-based filtering, but seems like it could also be a bit confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're probably right ... I'll log everything at info

continue;
}
if (rec.ruleMetadata() == null || rec.filePath().equals(".")) {
continue; // Always drop rules without metadata or the stats recomendation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add an option to keep the recommendations that don't have any metadata? I think it's great to drop them, but until a better mechanism exists, this will hide the problem under the rug. With such an option we can still enable it in end-to-end regression testing and alert.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather fix this by making sure all rules have metadata. If there is no metadata, we don't know what rule it is, so we can't filter it. Usually, these are low severity, so customers who want to block pipelines using the CLI would likely suppress them anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and this only happens when you filter. So we can still get these by running without filter. OK, that's good enough.

@martinschaef martinschaef requested a review from awsgaucho July 1, 2022 12:30
@martinschaef martinschaef merged commit d3476f5 into aws:main Jul 1, 2022
@martinschaef martinschaef deleted the codeinsights branch July 1, 2022 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0