mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-23 20:42:02 +00:00
refactor(azure): remove validate_arguments for CLI (#4985)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from argparse import ArgumentTypeError, Namespace
|
||||
from argparse import ArgumentTypeError
|
||||
|
||||
|
||||
def init_parser(self):
|
||||
@@ -68,37 +68,3 @@ def validate_azure_region(region):
|
||||
f"Region {region} not allowed, allowed regions are {' '.join(regions_allowed)}"
|
||||
)
|
||||
return region
|
||||
|
||||
|
||||
def validate_arguments(args: Namespace) -> tuple[bool, str]:
|
||||
"""
|
||||
Validates the authentication arguments for the Azure provider.
|
||||
|
||||
Args:
|
||||
args (Namespace): The parsed arguments from the Azure provider.
|
||||
|
||||
Returns:
|
||||
tuple[bool, str]: A tuple containing a boolean indicating if the arguments are valid and a string with an error message if the arguments are invalid
|
||||
"""
|
||||
if not args.browser_auth and args.tenant_id:
|
||||
return (
|
||||
False,
|
||||
"Azure Tenant ID (--tenant-id) is required for browser authentication mode",
|
||||
)
|
||||
elif (
|
||||
not args.az_cli_auth
|
||||
and not args.sp_env_auth
|
||||
and not args.browser_auth
|
||||
and not args.managed_identity_auth
|
||||
):
|
||||
return (
|
||||
False,
|
||||
"Azure provider requires at least one authentication method set: [--az-cli-auth | --sp-env-auth | --browser-auth | --managed-identity-auth]",
|
||||
)
|
||||
elif args.browser_auth and not args.tenant_id:
|
||||
return (
|
||||
False,
|
||||
"Azure Tenant ID (--tenant-id) is required for browser authentication mode",
|
||||
)
|
||||
|
||||
return (True, "")
|
||||
|
||||
@@ -238,11 +238,8 @@ class Test_Parser:
|
||||
|
||||
def test_root_parser_azure_provider(self):
|
||||
command = [prowler_command, "azure"]
|
||||
# Expecting a SystemExit exception
|
||||
with pytest.raises(SystemExit) as wrapped_exit:
|
||||
_ = self.parser.parse(command)
|
||||
assert wrapped_exit.type == SystemExit
|
||||
assert wrapped_exit.value.code == 2
|
||||
parsed = self.parser.parse(command)
|
||||
assert parsed.provider == "azure"
|
||||
|
||||
def test_root_parser_gcp_provider(self):
|
||||
command = [prowler_command, "gcp"]
|
||||
@@ -1110,22 +1107,18 @@ class Test_Parser:
|
||||
|
||||
def test_parser_azure_auth_browser(self):
|
||||
argument = "--browser-auth"
|
||||
# Expected to raise an error
|
||||
command = [prowler_command, "azure", argument]
|
||||
with pytest.raises(SystemExit) as wrapped_exit:
|
||||
_ = self.parser.parse(command)
|
||||
assert wrapped_exit.type == SystemExit
|
||||
assert wrapped_exit.value.code == 2
|
||||
parser = self.parser.parse(command)
|
||||
assert parser.provider == "azure"
|
||||
assert parser.browser_auth
|
||||
|
||||
def test_parser_azure_tenant_id(self):
|
||||
argument = "--tenant-id"
|
||||
tenant_id = "test-tenant-id"
|
||||
command = [prowler_command, "azure", argument, tenant_id]
|
||||
# Expected to raise an error
|
||||
with pytest.raises(SystemExit) as wrapped_exit:
|
||||
_ = self.parser.parse(command)
|
||||
assert wrapped_exit.type == SystemExit
|
||||
assert wrapped_exit.value.code == 2
|
||||
parsed = self.parser.parse(command)
|
||||
assert parsed.provider == "azure"
|
||||
assert parsed.tenant_id == tenant_id
|
||||
|
||||
def test_parser_azure_auth_az_cli(self):
|
||||
argument = "--az-cli-auth"
|
||||
|
||||
Reference in New Issue
Block a user