fix(config): path error in Windows environment (#1684)

Co-authored-by: sergargar <sergio@verica.io>
This commit is contained in:
Sergio Garcia
2023-01-10 17:06:14 +01:00
committed by GitHub
parent 50dd2e4179
commit 92cc2c8e69
4 changed files with 20 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
import os
import pathlib
from datetime import datetime, timezone
from os import getcwd
@@ -30,7 +30,8 @@ csv_file_suffix = ".csv"
json_file_suffix = ".json"
json_asff_file_suffix = ".asff.json"
html_file_suffix = ".html"
config_yaml = f"{os.path.dirname(os.path.realpath(__file__))}/config.yaml"
config_yaml = f"{pathlib.Path().absolute()}/prowler/config/config.yaml"
print(config_yaml)
def change_config_var(variable, value):
@@ -59,10 +60,10 @@ def get_config_var(variable):
def get_aws_available_regions():
try:
actual_directory = ("/").join(
os.path.dirname(os.path.realpath(__file__)).split("/")[:-1]
actual_directory = pathlib.Path().absolute()
f = open_file(
f"{actual_directory}/prowler/providers/aws/{aws_services_json_file}"
)
f = open_file(f"{actual_directory}/providers/aws/{aws_services_json_file}")
data = parse_json_file(f)
regions = set()

View File

@@ -1,4 +1,4 @@
import os
import pathlib
import sys
from boto3 import session
@@ -108,8 +108,10 @@ def generate_regional_clients(
try:
regional_clients = {}
# Get json locally
actual_directory = os.path.dirname(os.path.realpath(__file__))
f = open_file(f"{actual_directory}/{aws_services_json_file}")
actual_directory = pathlib.Path().absolute()
f = open_file(
f"{actual_directory}/prowler/providers/aws/{aws_services_json_file}"
)
data = parse_json_file(f)
# Check if it is a subservice
json_regions = data["services"][service]["regions"][

View File

@@ -1,4 +1,4 @@
import os
import pathlib
from importlib.machinery import FileFinder
from pkgutil import ModuleInfo
@@ -107,7 +107,7 @@ class Test_Check:
test_cases = [
{
"input": {
"metadata_path": f"{os.path.dirname(os.path.realpath(__file__))}/fixtures/metadata.json",
"metadata_path": f"{pathlib.Path().absolute()}/tests/lib/check/fixtures/metadata.json",
},
"expected": {
"CheckID": "iam_disable_30_days_credentials",
@@ -129,7 +129,7 @@ class Test_Check:
test_cases = [
{
"input": {
"path": f"{os.path.dirname(os.path.realpath(__file__))}/fixtures/checklistA.json",
"path": f"{pathlib.Path().absolute()}/tests/lib/check/fixtures/checklistA.json",
"provider": "aws",
},
"expected": {"check11", "check12", "check7777"},
@@ -263,7 +263,7 @@ class Test_Check:
# }
# with mock.patch(
# "prowler.lib.check.check.compliance_specification_dir_path",
# new=f"{os.path.dirname(os.path.realpath(__file__))}/fixtures",
# new=f"{pathlib.Path().absolute()}/fixtures",
# ):
# provider = "aws"
# bulk_compliance_frameworks = bulk_load_compliance_frameworks(provider)
@@ -286,7 +286,7 @@ class Test_Check:
# }
# with mock.patch(
# "prowler.lib.check.check.compliance_specification_dir",
# new=f"{os.path.dirname(os.path.realpath(__file__))}/fixtures",
# new=f"{pathlib.Path().absolute()}/fixtures",
# ):
# provider = "aws"
# bulk_compliance_frameworks = bulk_load_compliance_frameworks(provider)
@@ -305,7 +305,7 @@ class Test_Check:
# }
# with mock.patch(
# "prowler.lib.check.check.compliance_specification_dir",
# new=f"{os.path.dirname(os.path.realpath(__file__))}/fixtures",
# new=f"{pathlib.Path().absolute()}/fixtures",
# ):
# provider = "aws"
# bulk_compliance_frameworks = bulk_load_compliance_frameworks(provider)

View File

@@ -1,4 +1,4 @@
import os
import pathlib
from os import path, remove
from unittest import mock
@@ -66,7 +66,7 @@ def mock_make_api_call(self, operation_name, kwarg):
class Test_Outputs:
def test_fill_file_descriptors(self):
audited_account = AWS_ACCOUNT_ID
output_directory = f"{os.path.dirname(os.path.realpath(__file__))}"
output_directory = f"{pathlib.Path().absolute()}"
audit_info = AWS_Audit_Info(
original_session=None,
audit_session=None,
@@ -334,7 +334,7 @@ class Test_Outputs:
# Create mock csv output file
fixtures_dir = "fixtures"
output_directory = (
f"{os.path.dirname(os.path.realpath(__file__))}/{fixtures_dir}"
f"{pathlib.Path().absolute()}/tests/lib/outputs/{fixtures_dir}"
)
output_mode = "csv"
filename = f"prowler-output-{input_audit_info.audited_account}"