chore(version): check latest version (#2106)

This commit is contained in:
Sergio Garcia
2023-03-21 11:16:13 +01:00
committed by GitHub
parent 51eacbfac5
commit 706d723703
3 changed files with 26 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ import pathlib
from datetime import datetime, timezone
from os import getcwd
import requests
import yaml
from prowler.lib.logger import logger
@@ -43,6 +44,19 @@ html_file_suffix = ".html"
config_yaml = f"{pathlib.Path(os.path.dirname(os.path.realpath(__file__)))}/config.yaml"
def check_current_version(prowler_version):
try:
latest_version = requests.get(
"https://api.github.com/repos/prowler-cloud/prowler/tags"
).json()[0]["name"]
if latest_version != prowler_version:
return f"(latest is {latest_version}, upgrade for the latest features)"
else:
return "(it is the latest version, yay!)"
except Exception:
return ""
def change_config_var(variable, value):
try:
with open(config_yaml) as f:

View File

@@ -4,6 +4,7 @@ from argparse import RawTextHelpFormatter
from prowler.config.config import (
available_compliance_frameworks,
check_current_version,
default_output_directory,
prowler_version,
)
@@ -36,7 +37,7 @@ Detailed documentation at https://docs.prowler.cloud
"-v",
"--version",
action="version",
version=f"Prowler {prowler_version}",
version=f"Prowler {prowler_version} {check_current_version(prowler_version)}",
help="show Prowler version",
)
# Common arguments parser

View File

@@ -1,6 +1,16 @@
from prowler.config.config import check_current_version, prowler_version
from prowler.providers.aws.aws_provider import get_aws_available_regions
class Test_Config:
def test_get_aws_available_regions(self):
assert len(get_aws_available_regions()) == 31
def test_check_current_version(self):
assert (
check_current_version(prowler_version) == "(it is the latest version, yay!)"
)
assert (
check_current_version("0.0.0")
== f"(latest is {prowler_version}, upgrade for the latest features)"
)