Repository: prowler-cloud/prowler
Pull request: chore(quick-inventory): send quick inventory to output bucket
### Description

Send quick inventory to output bucket

### License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.


Problem statement:
[Bug]: using -D to send output to S3 does not work with -i for inventory
### Steps to Reproduce

1 - prowler -i -R rolename -D bucketname
2 - aws
3 - all work but nothing is pushed to s3 while if we remove -i we got the security check in S3

### Expected behavior

same as we are getting output files when doing security check we get inventory 

### Actual Result with Screenshots or Logs

no error in logs

### How did you install Prowler?

From pip package (pip install prowler)

### Environment Resource

ec2 instance

### OS used

ubuntu

### Prowler version

3.3.4

### Pip version

pip 22.3.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

### Context

_No response_

Hints from issue discussion:

Commit message: send inventory to output bucket

Patch to review:
diff --git a/prowler/__main__.py b/prowler/__main__.py
index 6ac7a74156..a77f1f3093 100644
--- a/prowler/__main__.py
+++ b/prowler/__main__.py
@@ -154,7 +154,7 @@ def prowler():
 
     # Run the quick inventory for the provider if available
     if hasattr(args, "quick_inventory") and args.quick_inventory:
-        run_provider_quick_inventory(provider, audit_info, args.output_directory)
+        run_provider_quick_inventory(provider, audit_info, args)
         sys.exit()
 
     # Execute checks
diff --git a/prowler/providers/aws/lib/quick_inventory/quick_inventory.py b/prowler/providers/aws/lib/quick_inventory/quick_inventory.py
index b87c8ccee8..6d243158cc 100644
--- a/prowler/providers/aws/lib/quick_inventory/quick_inventory.py
+++ b/prowler/providers/aws/lib/quick_inventory/quick_inventory.py
@@ -14,11 +14,12 @@
     output_file_timestamp,
 )
 from prowler.lib.logger import logger
+from prowler.lib.outputs.outputs import send_to_s3_bucket
 from prowler.providers.aws.lib.arn.models import get_arn_resource_type
 from prowler.providers.aws.lib.audit_info.models import AWS_Audit_Info
 
 
-def quick_inventory(audit_info: AWS_Audit_Info, output_directory: str):
+def quick_inventory(audit_info: AWS_Audit_Info, args):
     resources = []
     global_resources = []
     total_resources_per_region = {}
@@ -113,7 +114,7 @@ def quick_inventory(audit_info: AWS_Audit_Info, output_directory: str):
     )
     print(f"\nTotal resources found: {Fore.GREEN}{len(resources)}{Style.RESET_ALL}")
 
-    create_output(resources, audit_info, output_directory)
+    create_output(resources, audit_info, args)
 
 
 def create_inventory_table(resources: list, resources_in_region: dict) -> dict:
@@ -203,9 +204,11 @@ def create_inventory_table(resources: list, resources_in_region: dict) -> dict:
     return inventory_table
 
 
-def create_output(resources: list, audit_info: AWS_Audit_Info, output_directory: str):
+def create_output(resources: list, audit_info: AWS_Audit_Info, args):
     json_output = []
-    output_file = f"{output_directory}/prowler-inventory-{audit_info.audited_account}-{output_file_timestamp}"
+    output_file = (
+        f"prowler-inventory-{audit_info.audited_account}-{output_file_timestamp}"
+    )
 
     for item in sorted(resources, key=lambda d: d["arn"]):
         resource = {}
@@ -244,10 +247,14 @@ def create_output(resources: list, audit_info: AWS_Audit_Info, output_directory:
     json_object = json.dumps(json_output, indent=4)
 
     # Writing to sample.json
-    with open(output_file + json_file_suffix, "w") as outfile:
+    with open(
+        args.output_directory + "/" + output_file + json_file_suffix, "w"
+    ) as outfile:
         outfile.write(json_object)
 
-    csv_file = open(output_file + csv_file_suffix, "w", newline="")
+    csv_file = open(
+        args.output_directory + "/" + output_file + csv_file_suffix, "w", newline=""
+    )
     csv_writer = csv.writer(csv_file)
 
     count = 0
@@ -261,8 +268,25 @@ def create_output(resources: list, audit_info: AWS_Audit_Info, output_directory:
     csv_file.close()
 
     print("\nMore details in files:")
-    print(f" - CSV: {output_file+csv_file_suffix}")
-    print(f" - JSON: {output_file+json_file_suffix}")
+    print(f" - CSV: {args.output_directory}/{output_file+csv_file_suffix}")
+    print(f" - JSON: {args.output_directory}/{output_file+json_file_suffix}")
+
+    # Send output to S3 if needed (-B / -D)
+    for mode in ["json", "csv"]:
+        if args.output_bucket or args.output_bucket_no_assume:
+            output_bucket = args.output_bucket
+            bucket_session = audit_info.audit_session
+            # Check if -D was input
+            if args.output_bucket_no_assume:
+                output_bucket = args.output_bucket_no_assume
+                bucket_session = audit_info.original_session
+            send_to_s3_bucket(
+                output_file,
+                args.output_directory,
+                mode,
+                output_bucket,
+                bucket_session,
+            )
 
 
 def get_regional_buckets(audit_info: AWS_Audit_Info, region: str) -> list:
diff --git a/prowler/providers/common/quick_inventory.py b/prowler/providers/common/quick_inventory.py
index de2fb7b811..bf8e6fbfc4 100644
--- a/prowler/providers/common/quick_inventory.py
+++ b/prowler/providers/common/quick_inventory.py
@@ -5,7 +5,7 @@
 from prowler.providers.aws.lib.quick_inventory.quick_inventory import quick_inventory
 
 
-def run_provider_quick_inventory(provider, audit_info, output_directory):
+def run_provider_quick_inventory(provider, audit_info, args):
     """
     run_provider_quick_inventory executes the quick inventory for the provider
     """
@@ -13,7 +13,7 @@ def run_provider_quick_inventory(provider, audit_info, output_directory):
         # Dynamically get the Provider quick inventory handler
         provider_quick_inventory_function = f"{provider}_quick_inventory"
         getattr(importlib.import_module(__name__), provider_quick_inventory_function)(
-            audit_info, output_directory
+            audit_info, args
         )
     except Exception as error:
         logger.critical(
@@ -22,5 +22,5 @@ def run_provider_quick_inventory(provider, audit_info, output_directory):
         sys.exit(1)
 
 
-def aws_quick_inventory(audit_info, output_directory):
-    quick_inventory(audit_info, output_directory)
+def aws_quick_inventory(audit_info, args):
+    quick_inventory(audit_info, args)


Code review comments:
diff_hunk: @@ -261,8 +268,25 @@ def create_output(resources: list, audit_info: AWS_Audit_Info, output_directory:
     csv_file.close()
 
     print("\nMore details in files:")
-    print(f" - CSV: {output_file+csv_file_suffix}")
-    print(f" - JSON: {output_file+json_file_suffix}")
+    print(f" - CSV: {args.output_directory}/{output_file+csv_file_suffix}")
+    print(f" - JSON: {args.output_directory}/{output_file+json_file_suffix}")
+
+    # Send output to S3 if needed (-B / -D)
+    for mode in ["json", "csv"]:
+        if args.output_bucket or args.output_bucket_no_assume:
+            output_bucket = args.output_bucket
+            bucket_session = audit_info.audit_session
+            # Check if -D was input
+            if args.output_bucket_no_assume:
+                output_bucket = args.output_bucket_no_assume
+                bucket_session = audit_info.original_session
path: prowler/providers/aws/lib/quick_inventory/quick_inventory.py
text: @user1:
```suggestion
        if args.output_bucket or args.output_bucket_no_assume:
            # Check if -B was input
            if args.output_bucket:
                output_bucket = args.output_bucket
                bucket_session = audit_info.audit_session
            # Check if -D was input
            elif args.output_bucket_no_assume:
                output_bucket = args.output_bucket_no_assume
                bucket_session = audit_info.original_session
```