diff --git a/entrypoint.sh b/entrypoint.sh index a848801..53fb8a1 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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)