From 7cf3646cc09e05051bb64ee39be28481dfd7b46c Mon Sep 17 00:00:00 2001 From: EC2 Default User Date: Mon, 12 Aug 2024 08:38:43 +0000 Subject: [PATCH] Support Python versions from 3.8 to 3.12 & change inquirer library --- main.py | 32 +++++++++++++------------------- models.py | 5 +++-- requirements.txt | 11 +++++------ 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/main.py b/main.py index e1ec865..602233b 100644 --- a/main.py +++ b/main.py @@ -1,39 +1,33 @@ -import json -from pprint import pprint - -from PyInquirer import prompt, style_from_dict, Token +from InquirerLib import prompt +from InquirerLib.InquirerPy.utils import InquirerPyKeybindings +from InquirerLib.InquirerPy.base import Choice from colorama import Style, Fore from utils import * import services -custom_style_2 = style_from_dict( - { - Token.Separator: "#6C6C6C", - Token.QuestionMark: "#FF9D00 bold", - # Token.Selected: '', # default - Token.Selected: "#5F819D", - Token.Pointer: "#FF9D00 bold", - Token.Instruction: "", # default - Token.Answer: "#5F819D bold", - Token.Question: "", - } -) + +prompt_key_bindings: InquirerPyKeybindings = { + "toggle-all-true": [{"key": "a"}], + "toggle-all-false": [{"key": "A"}], + "toggle-all": [{"key": "i"}], +} def ask_services_to_enable(bp): cli_questions = [ { "type": "checkbox", - "message": "Select AWS Services to inspect", + "message": "Select AWS Services to inspect.", "name": "services", "choices": [ - {"name": k, "checked": bool(v["enabled"])} for k, v in bp.items() + Choice(service_name, enabled=bool(v["enabled"])) + for service_name, v in bp.items() ], } ] - answers = prompt(questions=cli_questions, style=custom_style_2) + answers = prompt(questions=cli_questions, keybindings=prompt_key_bindings) for service in bp.keys(): bp[service]["enabled"] = service in answers["services"] return bp diff --git a/models.py b/models.py index 64ff21d..0af4edb 100644 --- a/models.py +++ b/models.py @@ -1,7 +1,8 @@ from pydantic import BaseModel +from typing import List class RuleCheckResult(BaseModel): passed: bool - compliant_resources: list[str] - non_compliant_resources: list[str] + compliant_resources: List[str] + non_compliant_resources: List[str] diff --git a/requirements.txt b/requirements.txt index 485ab9c..0ac2c76 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,14 @@ annotated-types==0.7.0 -boto3==1.34.153 -botocore==1.34.153 +boto3==1.34.158 +botocore==1.34.158 colorama==0.4.6 +InquirerLib==0.0.2 jmespath==1.0.1 -prompt-toolkit==1.0.14 +pfzy==0.3.4 +prompt_toolkit==3.0.47 pydantic==2.8.2 pydantic_core==2.20.1 -Pygments==2.18.0 -PyInquirer==1.0.3 python-dateutil==2.9.0.post0 -regex==2024.7.24 s3transfer==0.10.2 six==1.16.0 typing_extensions==4.12.2