Skip to content

Commit

Permalink
Merge pull request #1 from aws-actions/v1-fixes
Browse files Browse the repository at this point in the history
Bug fixes, documentation updates and json file support
  • Loading branch information
serresebastien committed Oct 12, 2023
2 parents 574f08c + 5c0b89e commit b5400e8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ In your Github worflows, under steps, add the following:

```yml
name: AWS Sustainability Scanner
uses: aws-actions/sustainability-scanner@latest
uses: aws-actions/sustainability-scanner@v1
with:
<INPUTS>
```
Expand All @@ -21,7 +21,7 @@ Path to the specific file you want to scan.

### `directory`

Path to the directory you want to scan. Every `.yml` and `.yaml` files that this directory contain will be scan.
Path to the directory you want to scan. Every `.json`, `.yml` and `.yaml` files that this directory contain will be scan.

### `rules_file`

Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
# Run AWS Sustainability Scanner against template.yaml
- name: AWS Sustainability Scanner
uses: aws-actions/sustainability-scanner@latest
uses: aws-actions/sustainability-scanner@v1
with:
file: 'template.yaml'
```
Expand All @@ -81,9 +81,9 @@ jobs:
# Run AWS Sustainability Scanner against "my-cf-stacks" folder with an additional rules set
- name: AWS Sustainability Scanner
uses: aws-actions/sustainability-scanner@latest
uses: aws-actions/sustainability-scanner@v1
with:
directory: 'my-cf-stacks/'
directory: 'my-cf-stacks'
rules-file: 'tests/additional-rules.json'
```

Expand Down
12 changes: 6 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# action.yml
name: 'AWS Sustainability Scanner GitHub Action'
author: 'AWS Sustainability'
description: 'Run AWS Sustainability Scan against infrastructure as code as a pre-packaged GitHub Action.'
description: 'Run AWS Sustainability Scanner against infrastructure as code as a pre-packaged GitHub Action.'
branding:
icon: 'cloud'
color: 'orange'
inputs:
file:
description: 'File with infrastructure code to scan'
required: true
directory:
description: 'Directory with infrastructure code to scan'
description: 'File path of template to scan'
required: false
directory:
description: 'Directory path with template files to scan'
required: true
default: '.'
rules_file:
description: 'File to extend set of rules to scan'
description: 'File path to extend set of rules'
required: false
outputs:
results:
Expand Down
27 changes: 19 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,31 @@ fi
# Create an empty array to store file names to scan
RESOURCES_TO_SCAN=()

# If File Variable exists then scan the specific resource
# If INPUT_FILE variable exists then scan the specific resource
if [ -n "$INPUT_FILE" ]; then
RESOURCES_TO_SCAN+=("$INPUT_FILE")
else
# Otherwise scan directory provided (root by default) to populate the array with all .yml or .yaml files
echo "running susscanner on directory: $INPUT_DIRECTORY"
for FILE in "$INPUT_DIRECTORY"/*.yaml "$INPUT_DIRECTORY"/*.yml; do
RESOURCES_TO_SCAN+=("$FILE")
done
# Otherwise scan directory provided (root by default)
if [ -d "$INPUT_DIRECTORY" ]; then
# Use 'find' to search for YAML and JSON files inside the directory
while IFS= read -r -d $'\0' file; do
RESOURCES_TO_SCAN+=("$file")
done < <(find "$INPUT_DIRECTORY" -type f \( -name "*.json" -o -name "*.yaml" -o -name "*.yml" \) -print0)

# Check if any files were found
if [ -n "$RESOURCES_TO_SCAN" ]; then
echo "${#RESOURCES_TO_SCAN[@]} file(s) found in directory: $INPUT_DIRECTORY"
else
echo "No template files found in directory: $INPUT_DIRECTORY"
fi
else
echo "Directory not found: $INPUT_DIRECTORY"
fi
fi

# Build command
for RESOURCE in $RESOURCES_TO_SCAN; do
echo "running susscanner on file: $RESOURCE"
for RESOURCE in "${RESOURCES_TO_SCAN[@]}"; do
echo "Running susscanner on file: $RESOURCE"
echo "susscanner $RESOURCE $RULES_FILE"
SUSSCAN_RESULTS=$(susscanner $RESOURCE $RULES_FILE)

Expand Down

0 comments on commit b5400e8

Please sign in to comment.