prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  [Bug]: The check 'Potential secret found in EC2 instance * User Data.' does not include the line numbers where the secrets were found
  ### Steps to Reproduce
  
  The check 'Potential secret found in EC2 instance * User Data.' does not show the line numbers, whereas 'Potential secret found in variables of ECS task definition' does. Why is it so?
  
  The results of check without precise pointing at the line are frustrating: you do not know where exactly the scanner found the secret and how many secrets were found.
  
  Same issue will rise if you need to troubleshoot the scanner.
  
  ### Expected behavior
  
  Numbers of lines with secrets are included in issue description.
  
  ### Actual Result with Screenshots or Logs
  
  -
  
  ### How did you install Prowler?
  
  Docker (docker pull toniblyx/prowler)
  
  ### Environment Resource
  
  Fargate
  
  ### OS used
  
  --
  
  ### Prowler version
  
  3
  
  ### Pip version
  
  --
  
  ### Context
  
  _No response_
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `prowler/providers/aws/services/ec2/ec2_instance_secrets_user_data/ec2_instance_secrets_user_data.py`
  Content:
  ```
  1 import os
  2 import tempfile
  3 import zlib
  4 from base64 import b64decode
  5 
  6 from detect_secrets import SecretsCollection
  7 from detect_secrets.settings import default_settings
  8 
  9 from prowler.lib.check.models import Check, Check_Report_AWS
  10 from prowler.providers.aws.services.ec2.ec2_client import ec2_client
  11 
  12 
  13 class ec2_instance_secrets_user_data(Check):
  14     def execute(self):
  15         findings = []
  16         for instance in ec2_client.instances:
  17             if instance.state != "terminated":
  18                 report = Check_Report_AWS(self.metadata())
  19                 report.region = instance.region
  20                 report.resource_id = instance.id
  21                 report.resource_arn = instance.arn
  22                 report.resource_tags = instance.tags
  23                 if instance.user_data:
  24                     temp_user_data_file = tempfile.NamedTemporaryFile(delete=False)
  25                     user_data = b64decode(instance.user_data)
  26                     if user_data[0:2] == b"\x1f\x8b":  # GZIP magic number
  27                         user_data = zlib.decompress(
  28                             user_data, zlib.MAX_WBITS | 32
  29                         ).decode("utf-8")
  30                     else:
  31                         user_data = user_data.decode("utf-8")
  32 
  33                     temp_user_data_file.write(
  34                         bytes(user_data, encoding="raw_unicode_escape")
  35                     )
  36                     temp_user_data_file.close()
  37                     secrets = SecretsCollection()
  38                     with default_settings():
  39                         secrets.scan_file(temp_user_data_file.name)
  40 
  41                     if secrets.json():
  42                         report.status = "FAIL"
  43                         report.status_extended = f"Potential secret found in EC2 instance {instance.id} User Data."
  44                     else:
  45                         report.status = "PASS"
  46                         report.status_extended = (
  47                             f"No secrets found in EC2 instance {instance.id} User Data."
  48                         )
  49 
  50                     os.remove(temp_user_data_file.name)
  51                 else:
  52                     report.status = "PASS"
  53                     report.status_extended = f"No secrets found in EC2 instance {instance.id} since User Data is empty."
  54 
  55                 findings.append(report)
  56 
  57         return findings
  58
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/prowler/providers/aws/services/ec2/ec2_instance_secrets_user_data/ec2_instance_secrets_user_data.py b/prowler/providers/aws/services/ec2/ec2_instance_secrets_user_data/ec2_instance_secrets_user_data.py
  --- a/prowler/providers/aws/services/ec2/ec2_instance_secrets_user_data/ec2_instance_secrets_user_data.py
  +++ b/prowler/providers/aws/services/ec2/ec2_instance_secrets_user_data/ec2_instance_secrets_user_data.py
  @@ -38,9 +38,19 @@
                       with default_settings():
                           secrets.scan_file(temp_user_data_file.name)
   
  -                    if secrets.json():
  +                    detect_secrets_output = secrets.json()
  +                    if detect_secrets_output:
  +                        secrets_string = ", ".join(
  +                            [
  +                                f"{secret['type']} on line {secret['line_number']}"
  +                                for secret in detect_secrets_output[
  +                                    temp_user_data_file.name
  +                                ]
  +                            ]
  +                        )
                           report.status = "FAIL"
  -                        report.status_extended = f"Potential secret found in EC2 instance {instance.id} User Data."
  +                        report.status_extended = f"Potential secret found in EC2 instance {instance.id} User Data -> {secrets_string}."
  +
                       else:
                           report.status = "PASS"
                           report.status_extended = (
  
verification_info: {"golden_diff": "diff --git a/prowler/providers/aws/services/ec2/ec2_instance_secrets_user_data/ec2_instance_secrets_user_data.py b/prowler/providers/aws/services/ec2/ec2_instance_secrets_user_data/ec2_instance_secrets_user_data.py\n--- a/prowler/providers/aws/services/ec2/ec2_instance_secrets_user_data/ec2_instance_secrets_user_data.py\n+++ b/prowler/providers/aws/services/ec2/ec2_instance_secrets_user_data/ec2_instance_secrets_user_data.py\n@@ -38,9 +38,19 @@\n                     with default_settings():\n                         secrets.scan_file(temp_user_data_file.name)\n \n-                    if secrets.json():\n+                    detect_secrets_output = secrets.json()\n+                    if detect_secrets_output:\n+                        secrets_string = \", \".join(\n+                            [\n+                                f\"{secret['type']} on line {secret['line_number']}\"\n+                                for secret in detect_secrets_output[\n+                                    temp_user_data_file.name\n+                                ]\n+                            ]\n+                        )\n                         report.status = \"FAIL\"\n-                        report.status_extended = f\"Potential secret found in EC2 instance {instance.id} User Data.\"\n+                        report.status_extended = f\"Potential secret found in EC2 instance {instance.id} User Data -> {secrets_string}.\"\n+\n                     else:\n                         report.status = \"PASS\"\n                         report.status_extended = (\n", "issue": "[Bug]: The check 'Potential secret found in EC2 instance * User Data.' does not include the line numbers where the secrets were found\n### Steps to Reproduce\n\nThe check 'Potential secret found in EC2 instance * User Data.' does not show the line numbers, whereas 'Potential secret found in variables of ECS task definition' does. Why is it so?\r\n\r\nThe results of check without precise pointing at the line are frustrating: you do not know where exactly the scanner found the secret and how many secrets were found.\r\n\r\nSame issue will rise if you need to troubleshoot the scanner.\n\n### Expected behavior\n\nNumbers of lines with secrets are included in issue description.\n\n### Actual Result with Screenshots or Logs\n\n-\n\n### How did you install Prowler?\n\nDocker (docker pull toniblyx/prowler)\n\n### Environment Resource\n\nFargate\n\n### OS used\n\n--\n\n### Prowler version\n\n3\n\n### Pip version\n\n--\n\n### Context\n\n_No response_\n", "before_files": [{"content": "import os\nimport tempfile\nimport zlib\nfrom base64 import b64decode\n\nfrom detect_secrets import SecretsCollection\nfrom detect_secrets.settings import default_settings\n\nfrom prowler.lib.check.models import Check, Check_Report_AWS\nfrom prowler.providers.aws.services.ec2.ec2_client import ec2_client\n\n\nclass ec2_instance_secrets_user_data(Check):\n    def execute(self):\n        findings = []\n        for instance in ec2_client.instances:\n            if instance.state != \"terminated\":\n                report = Check_Report_AWS(self.metadata())\n                report.region = instance.region\n                report.resource_id = instance.id\n                report.resource_arn = instance.arn\n                report.resource_tags = instance.tags\n                if instance.user_data:\n                    temp_user_data_file = tempfile.NamedTemporaryFile(delete=False)\n                    user_data = b64decode(instance.user_data)\n                    if user_data[0:2] == b\"\\x1f\\x8b\":  # GZIP magic number\n                        user_data = zlib.decompress(\n                            user_data, zlib.MAX_WBITS | 32\n                        ).decode(\"utf-8\")\n                    else:\n                        user_data = user_data.decode(\"utf-8\")\n\n                    temp_user_data_file.write(\n                        bytes(user_data, encoding=\"raw_unicode_escape\")\n                    )\n                    temp_user_data_file.close()\n                    secrets = SecretsCollection()\n                    with default_settings():\n                        secrets.scan_file(temp_user_data_file.name)\n\n                    if secrets.json():\n                        report.status = \"FAIL\"\n                        report.status_extended = f\"Potential secret found in EC2 instance {instance.id} User Data.\"\n                    else:\n                        report.status = \"PASS\"\n                        report.status_extended = (\n                            f\"No secrets found in EC2 instance {instance.id} User Data.\"\n                        )\n\n                    os.remove(temp_user_data_file.name)\n                else:\n                    report.status = \"PASS\"\n                    report.status_extended = f\"No secrets found in EC2 instance {instance.id} since User Data is empty.\"\n\n                findings.append(report)\n\n        return findings\n", "path": "prowler/providers/aws/services/ec2/ec2_instance_secrets_user_data/ec2_instance_secrets_user_data.py"}], "after_files": [{"content": "import os\nimport tempfile\nimport zlib\nfrom base64 import b64decode\n\nfrom detect_secrets import SecretsCollection\nfrom detect_secrets.settings import default_settings\n\nfrom prowler.lib.check.models import Check, Check_Report_AWS\nfrom prowler.providers.aws.services.ec2.ec2_client import ec2_client\n\n\nclass ec2_instance_secrets_user_data(Check):\n    def execute(self):\n        findings = []\n        for instance in ec2_client.instances:\n            if instance.state != \"terminated\":\n                report = Check_Report_AWS(self.metadata())\n                report.region = instance.region\n                report.resource_id = instance.id\n                report.resource_arn = instance.arn\n                report.resource_tags = instance.tags\n                if instance.user_data:\n                    temp_user_data_file = tempfile.NamedTemporaryFile(delete=False)\n                    user_data = b64decode(instance.user_data)\n                    if user_data[0:2] == b\"\\x1f\\x8b\":  # GZIP magic number\n                        user_data = zlib.decompress(\n                            user_data, zlib.MAX_WBITS | 32\n                        ).decode(\"utf-8\")\n                    else:\n                        user_data = user_data.decode(\"utf-8\")\n\n                    temp_user_data_file.write(\n                        bytes(user_data, encoding=\"raw_unicode_escape\")\n                    )\n                    temp_user_data_file.close()\n                    secrets = SecretsCollection()\n                    with default_settings():\n                        secrets.scan_file(temp_user_data_file.name)\n\n                    detect_secrets_output = secrets.json()\n                    if detect_secrets_output:\n                        secrets_string = \", \".join(\n                            [\n                                f\"{secret['type']} on line {secret['line_number']}\"\n                                for secret in detect_secrets_output[\n                                    temp_user_data_file.name\n                                ]\n                            ]\n                        )\n                        report.status = \"FAIL\"\n                        report.status_extended = f\"Potential secret found in EC2 instance {instance.id} User Data -> {secrets_string}.\"\n\n                    else:\n                        report.status = \"PASS\"\n                        report.status_extended = (\n                            f\"No secrets found in EC2 instance {instance.id} User Data.\"\n                        )\n\n                    os.remove(temp_user_data_file.name)\n                else:\n                    report.status = \"PASS\"\n                    report.status_extended = f\"No secrets found in EC2 instance {instance.id} since User Data is empty.\"\n\n                findings.append(report)\n\n        return findings\n", "path": "prowler/providers/aws/services/ec2/ec2_instance_secrets_user_data/ec2_instance_secrets_user_data.py"}]}