fix(version): execute check current version function only when -v (#2263)

This commit is contained in:
Sergio Garcia
2023-04-24 12:45:59 +02:00
committed by GitHub
parent 63501a0d59
commit 8e63fa4594
3 changed files with 23 additions and 13 deletions

View File

@@ -46,19 +46,20 @@ html_file_suffix = ".html"
config_yaml = f"{pathlib.Path(os.path.dirname(os.path.realpath(__file__)))}/config.yaml"
def check_current_version(prowler_version):
def check_current_version():
try:
prowler_version_string = f"Prowler {prowler_version}"
release_response = requests.get(
"https://api.github.com/repos/prowler-cloud/prowler/tags"
)
latest_version = release_response.json()[0]["name"]
if latest_version != prowler_version:
return f"(latest is {latest_version}, upgrade for the latest features)"
return f"{prowler_version_string} (latest is {latest_version}, upgrade for the latest features)"
else:
return "(it is the latest version, yay!)"
except Exception as e:
print(e)
return ""
return f"{prowler_version_string} (it is the latest version, yay!)"
except Exception as error:
logger.error(f"{error.__class__.__name__}: {error}")
return f"{prowler_version_string}"
def change_config_var(variable, value):

View File

@@ -6,7 +6,6 @@ from prowler.config.config import (
available_compliance_frameworks,
check_current_version,
default_output_directory,
prowler_version,
)
from prowler.providers.aws.aws_provider import get_aws_available_regions
from prowler.providers.aws.lib.arn.arn import is_valid_arn
@@ -36,8 +35,7 @@ Detailed documentation at https://docs.prowler.cloud
self.parser.add_argument(
"-v",
"--version",
action="version",
version=f"Prowler {prowler_version} {check_current_version(prowler_version)}",
action="store_true",
help="show Prowler version",
)
# Common arguments parser
@@ -68,6 +66,10 @@ Detailed documentation at https://docs.prowler.cloud
if args:
sys.argv = args
if len(sys.argv) == 2 and sys.argv[1] in ("-v", "--version"):
print(check_current_version())
sys.exit(0)
# Set AWS as the default provider if no provider is supplied
if len(sys.argv) == 1:
sys.argv = self.__set_default_provider__(sys.argv)